public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
try
string workingdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.CompanyName, Application.ProductName);
string datapath = Path.Combine(workingdir, "Data");
string logopath = Path.Combine(datapath, "logo01.png");
string bannerpath = Path.Combine(datapath, "banner01.jpg");
string bgpath = Path.Combine(datapath, "defualt1.jpg");
string backupdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Application.CompanyName, Application.ProductName);
string dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.CompanyName, Application.ProductName);
string dbdir = Path.Combine(dbpath, "ItemBank.db");
string userpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.CompanyName, Application.ProductName, "userdata");
string exampath = Path.Combine(datapath, "Exams");
string configpath = Path.Combine(datapath, "config.gzsettings");
if (!Directory.Exists(exampath))
Directory.CreateDirectory(exampath);
if (!Directory.Exists(userpath))
Directory.CreateDirectory(userpath);
if (!Directory.Exists(dbpath))
Directory.CreateDirectory(dbpath);
if (!Directory.Exists(backupdir))
Directory.CreateDirectory(backupdir);
Logger loger = new Logger(workingdir);
if (File.Exists(@"Data\ItemBank.db"))
if (File.Exists(dbdir))
string file = Path.Combine(dbpath, "ItemBank_old.db");
if (File.Exists(file))
int i = 1;
do
file = string.Format("{0}\\ItemBank_old {1}.db", dbpath, i);
i++;
}
while (File.Exists(file));
File.Copy(dbdir, file);
File.Copy(@"Data\ItemBank.db", dbdir, true);
File.Copy(@"Data\ItemBank.db", backupdir + @"\ItemBank.db", true);
if (File.Exists(@"config.gzsettings"))
if (File.Exists(configpath))
string file = Path.Combine(datapath, "config_old.gzsettings");
file = string.Format("{0}\\config_old {1}.gzsettings", datapath, i);
File.Copy(configpath, file);
File.Copy(@"config.gzsettings", configpath, true);
File.Copy(@"config.gzsettings", backupdir + @"\config.gzsettings", true);
if (Directory.Exists(@"Data\Exams"))
foreach (string file in Directory.GetFiles(@"Data\Exams"))
int s = file.LastIndexOf("\\");
string pat = Path.Combine(exampath, file.Substring(s));
File.Copy(file, Path.Combine(backupdir, file.Substring(s)), true);
if (File.Exists(@"Data\default1.jpg"))
File.Copy(@"Data\default1.jpg", bgpath, true);
File.Copy(@"Data\default1.jpg", backupdir + @"\default1.jpg", true);
if (File.Exists(@"Data\logo01.jpg"))
File.Copy(@"Data\logo01.jpg", logopath, true);
File.Copy(@"Data\logo01.jpg", backupdir + @"\logo01.jpg", true);
RegistryKey rgk_paths = Application.UserAppDataRegistry.CreateSubKey("UsefulPaths");
rgk_paths.SetValue("usersettingspath", configpath);
rgk_paths.SetValue("itembankpath", dbdir);
rgk_paths.SetValue("appdatapath", datapath);
rgk_paths.SetValue("userdatapath", userpath);
rgk_paths.SetValue("backuppath", backupdir);
Settings settings = new Settings();
settings.Load(@"config.gzsettings");
settings["userinfofolderpath"] = userpath;
settings["appdatapath"] = datapath;
settings["ItemBankPath"] = dbdir;
settings["examfolderpath"] = exampath;
settings["LogoPath"] = logopath;
settings["BackgroundImagePath"] = bgpath;
settings["BarnerPath"] = bannerpath;
using (RegistryKey rgk_settings = Application.UserAppDataRegistry.CreateSubKey("defaultsettings"))
foreach (var key in settings.GetData().Keys)
rgk_settings.SetValue(key, settings[key]);
rgk_settings.Close();
settings.Save(backupdir + @"\config.gzsettings");
settings.Save(configpath);
catch (Exception e)
throw new ApplicationException("Database creation fault: \n" + e.Message);