2014-07-25 19:07:08 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-08-02 10:48:14 +01:00
|
|
|
|
using System.ComponentModel;
|
2014-07-27 20:58:49 +01:00
|
|
|
|
using System.Data;
|
2014-07-25 19:07:08 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Data.SqlServerCe;
|
2014-08-02 10:48:14 +01:00
|
|
|
|
using System.Windows.Forms;
|
2014-07-25 19:07:08 +01:00
|
|
|
|
|
2014-07-27 20:58:49 +01:00
|
|
|
|
|
2014-07-25 19:07:08 +01:00
|
|
|
|
namespace Saviour_Backup_System
|
|
|
|
|
{
|
|
|
|
|
class setup
|
|
|
|
|
{
|
2014-08-02 10:48:14 +01:00
|
|
|
|
static string databaseName = databaseTools.databaseName;
|
2014-08-05 16:44:49 +01:00
|
|
|
|
internal static string[] runtimeArguements = null;
|
2014-11-04 15:55:18 +00:00
|
|
|
|
internal static mainWindow MW;
|
2014-07-27 20:58:49 +01:00
|
|
|
|
|
2014-08-04 18:31:19 +01:00
|
|
|
|
internal static void initProgram(string[] args)
|
2014-08-02 10:48:14 +01:00
|
|
|
|
{
|
2014-11-04 15:55:18 +00:00
|
|
|
|
runtimeArguements = args;
|
|
|
|
|
|
|
|
|
|
notificationIcon icon = new notificationIcon();
|
|
|
|
|
if (args.Length == 0) //if the program is run out-right or not from startup
|
|
|
|
|
{
|
|
|
|
|
Application.Run(MW);
|
|
|
|
|
}
|
|
|
|
|
else if (args[0] == "STARTUP") //if the program is run when the computer starts up
|
|
|
|
|
{
|
|
|
|
|
Application.Run(MW);
|
|
|
|
|
MainUI = MW;
|
|
|
|
|
MW.Hide();
|
|
|
|
|
}
|
2014-08-02 10:48:14 +01:00
|
|
|
|
//if (!File.Exists(databaseName)) { setupDatabase(); } // If the program has been run before, then the database will exist, so use that to test it.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void setupDatabase(){
|
2014-07-25 19:07:08 +01:00
|
|
|
|
SqlCeEngine SQLEngine = new SqlCeEngine("Data Source = " + databaseName);
|
|
|
|
|
SQLEngine.CreateDatabase(); //Creates the database if it doesnt exist already
|
|
|
|
|
|
|
|
|
|
SqlCeConnection conn = new SqlCeConnection("Data Source = " + databaseName);
|
|
|
|
|
conn.Open();
|
|
|
|
|
SqlCeCommand cmd = conn.CreateCommand();
|
|
|
|
|
|
|
|
|
|
cmd.CommandText = "CREATE TABLE Rules (%%);"; //Fill these in! (Before running)
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
2014-07-27 20:58:49 +01:00
|
|
|
|
cmd.CommandText = "CREATE TABLE Properties (Property NTEXT PRIMARY KEY, value NTEXT);"; //Fill this one in too
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
fillDatabase(cmd, conn);
|
|
|
|
|
}
|
2014-08-02 10:48:14 +01:00
|
|
|
|
|
|
|
|
|
|
2014-07-27 20:58:49 +01:00
|
|
|
|
private static void fillDatabase(SqlCeCommand cmd, SqlCeConnection conn)
|
|
|
|
|
{
|
|
|
|
|
cmd.CommandText = "INSERT INTO Properties VALUES (?,?);";
|
|
|
|
|
cmd.Parameters.Add(new SqlCeParameter("PROPERTY", SqlDbType.Int));
|
|
|
|
|
cmd.Parameters.Add(new SqlCeParameter("VALUE", SqlDbType.NText));
|
|
|
|
|
|
|
|
|
|
cmd.Parameters["PROPERTY"].Value = "Startup";
|
|
|
|
|
cmd.Parameters["VALUE"].Value = "FALSE";
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
cmd.Parameters["PROPERTY"].Value = "";
|
|
|
|
|
cmd.Parameters["VALUE"].Value = "";
|
2014-07-25 19:07:08 +01:00
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
}
|
2014-08-02 10:48:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static void closeProgram(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
2014-11-04 15:55:18 +00:00
|
|
|
|
|
2014-08-02 10:48:14 +01:00
|
|
|
|
}
|
2014-07-25 19:07:08 +01:00
|
|
|
|
}
|
|
|
|
|
}
|