2014-07-24 16:42:30 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Data.SqlServerCe;
|
2014-11-07 00:39:42 +00:00
|
|
|
|
using System.Data;
|
2014-07-24 16:42:30 +01:00
|
|
|
|
using System.IO;
|
2014-11-09 18:18:09 +00:00
|
|
|
|
using Saviour_Backup_System.Properties;
|
2014-11-09 16:11:10 +00:00
|
|
|
|
|
2014-07-24 16:42:30 +01:00
|
|
|
|
namespace Saviour_Backup_System
|
|
|
|
|
{
|
2014-11-09 16:11:10 +00:00
|
|
|
|
class databaseTools
|
2014-07-24 16:42:30 +01:00
|
|
|
|
{
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public static string databaseName = "saviour.sdf";
|
|
|
|
|
public static SqlCeConnection conn = new SqlCeConnection("Data Source = " + databaseName + "; password=12a712d7e6f71ed07822c219318da2c0"); //password is a hash
|
2014-11-07 00:39:42 +00:00
|
|
|
|
private static SqlCeCommand cmd = conn.CreateCommand();
|
2014-07-24 20:27:22 +01:00
|
|
|
|
|
2014-11-09 18:18:09 +00:00
|
|
|
|
private static void copyDatabase()
|
2014-07-24 16:42:30 +01:00
|
|
|
|
{
|
2014-11-10 14:47:33 +00:00
|
|
|
|
File.WriteAllBytes(@"" + databaseName, Resources.saviour); //copy file from resources to project file
|
2014-11-09 18:18:09 +00:00
|
|
|
|
}
|
2014-11-07 00:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public static void init() {
|
2014-11-09 18:18:09 +00:00
|
|
|
|
if (!File.Exists(databaseName)) { //if the database doesnt exists (program hasnt been run before)
|
2014-11-10 14:47:33 +00:00
|
|
|
|
copyDatabase();
|
2014-11-09 18:18:09 +00:00
|
|
|
|
}
|
2014-07-24 16:42:30 +01:00
|
|
|
|
}
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public static backup[] getBackups()
|
2014-11-10 16:36:14 +00:00
|
|
|
|
{
|
|
|
|
|
List<backup> backups = null;
|
|
|
|
|
conn.Open();
|
|
|
|
|
cmd.CommandText = "";
|
|
|
|
|
SqlCeDataReader reader = cmd.ExecuteReader();
|
|
|
|
|
int index = 0;
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
backup temp = new backup();
|
|
|
|
|
backups.Add(temp);
|
|
|
|
|
temp = null;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
if (backups == null)
|
|
|
|
|
{
|
|
|
|
|
return new backup[0];
|
|
|
|
|
}
|
|
|
|
|
return backups.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 16:42:30 +01:00
|
|
|
|
}
|
2014-11-10 16:36:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class backup
|
|
|
|
|
{
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public string driveID;
|
|
|
|
|
public string name;
|
|
|
|
|
public Int64 startDate;
|
|
|
|
|
public string hash;
|
|
|
|
|
public Int32 duration;
|
2014-11-10 16:36:14 +00:00
|
|
|
|
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public void store()
|
2014-11-10 16:36:14 +00:00
|
|
|
|
{
|
|
|
|
|
SqlCeCommand cmd = databaseTools.conn.CreateCommand();
|
|
|
|
|
cmd.CommandText = "";
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public void update()
|
2014-11-10 16:36:14 +00:00
|
|
|
|
{
|
|
|
|
|
databaseTools.conn.Open();
|
|
|
|
|
SqlCeCommand cmd = databaseTools.conn.CreateCommand();
|
|
|
|
|
cmd.CommandText = "";
|
|
|
|
|
//execute reader or whatever it is
|
|
|
|
|
databaseTools.conn.Close();
|
|
|
|
|
cmd.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 22:55:14 +00:00
|
|
|
|
public void create(string Drive_ID, string Backup_Name, Int64 Start_Date, string Hash, Int32 Duration ) {
|
2014-11-10 16:36:14 +00:00
|
|
|
|
driveID = Drive_ID;
|
|
|
|
|
name = Backup_Name;
|
|
|
|
|
startDate = Start_Date;
|
|
|
|
|
hash = Hash;
|
|
|
|
|
duration = Duration;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-24 16:42:30 +01:00
|
|
|
|
}
|