Good day sirs/ma's
 
Please am trying to write a custom action library for vs 2010 installer. In the custom action's Install event, am trying to copy some files (among which is an sqlite database) to locations like the "AppData\Local\MySoftware" and some in the "My Document" folder. I know I should have used the "File System on Target Machine" property of the VS2010 Installer package and add those folders but I need to iterate through some list of files and add them to the "My Document" and the "MySoftware" folder plus I want to store the directory of each files into the registry.
 
I created a new class that inherited from the Installer Class and override the Install event, then put the bellow codes but none of the folders were created, not a single value was writen to the registry and no error was throw, the package installed successfully but those directories, folders and registry path were not created.
 
I tried calling the Install library(the custom action libraray I wrote) from the main form's Load event, it worked and all registry and folders were created, suggesting that nothing is wrong with my codes.
 
please help me.
 
Code
 public override void Install(System.Collections.IDictionary stateSaver)
Code
        {
Code
            base.Install(stateSaver);
Code
Code
            try
Code
            {
Code
                string workingdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.CompanyName, Application.ProductName);
Code
                string datapath = Path.Combine(workingdir, "Data");
Code
                string logopath = Path.Combine(datapath, "logo01.png");
Code
                string bannerpath = Path.Combine(datapath, "banner01.jpg");
Code
                string bgpath = Path.Combine(datapath, "defualt1.jpg");
Code
                string backupdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Application.CompanyName, Application.ProductName);
Code
                string dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.CompanyName, Application.ProductName);
Code
                string dbdir = Path.Combine(dbpath, "ItemBank.db");
Code
                string userpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.CompanyName, Application.ProductName, "userdata");
Code
                string exampath = Path.Combine(datapath, "Exams");
Code
                string configpath = Path.Combine(datapath, "config.gzsettings");
Code
                if (!Directory.Exists(exampath))
Code
                    Directory.CreateDirectory(exampath);
Code
                if (!Directory.Exists(userpath))
Code
                    Directory.CreateDirectory(userpath);
Code
                if (!Directory.Exists(dbpath))
Code
                    Directory.CreateDirectory(dbpath);
Code
                if (!Directory.Exists(backupdir))
Code
                    Directory.CreateDirectory(backupdir);
Code
                Logger loger = new Logger(workingdir);
Code
                if (File.Exists(@"Data\ItemBank.db"))
Code
                {
Code
                    if (File.Exists(dbdir))
Code
                    {
Code
                        string file = Path.Combine(dbpath, "ItemBank_old.db");
Code
                        if (File.Exists(file))
Code
                        {
Code
                            int i = 1;
Code
                            do
Code
                            {
Code
                                file = string.Format("{0}\\ItemBank_old {1}.db", dbpath, i);
Code
                                i++;
Code
                            }
Code
                            while (File.Exists(file));
Code
                        }
Code
                        File.Copy(dbdir, file);
Code
                    }
Code
                    File.Copy(@"Data\ItemBank.db", dbdir, true);
Code
                    File.Copy(@"Data\ItemBank.db", backupdir + @"\ItemBank.db", true);
Code
                }
Code
Code
                if (File.Exists(@"config.gzsettings"))
Code
                {
Code
                    if (File.Exists(configpath))
Code
                    {
Code
                        string file = Path.Combine(datapath, "config_old.gzsettings");
Code
                        if (File.Exists(file))
Code
                        {
Code
                            int i = 1;
Code
                            do
Code
                            {
Code
                                file = string.Format("{0}\\config_old {1}.gzsettings", datapath, i);
Code
                                i++;
Code
                            }
Code
                            while (File.Exists(file));
Code
                        }
Code
                        File.Copy(configpath, file);
Code
                    }
Code
                    File.Copy(@"config.gzsettings", configpath, true);
Code
                    File.Copy(@"config.gzsettings", backupdir + @"\config.gzsettings", true);
Code
                }
Code
                if (Directory.Exists(@"Data\Exams"))
Code
                {
Code
                    foreach (string file in Directory.GetFiles(@"Data\Exams"))
Code
                    {
Code
                        int s = file.LastIndexOf("\\");
Code
                        string pat = Path.Combine(exampath, file.Substring(s));
Code
                        File.Copy(file, Path.Combine(backupdir, file.Substring(s)), true);
Code
                    }
Code
                }
Code
                if (File.Exists(@"Data\default1.jpg"))
Code
                {
Code
                    File.Copy(@"Data\default1.jpg", bgpath, true);
Code
                    File.Copy(@"Data\default1.jpg", backupdir + @"\default1.jpg", true);
Code
                }
Code
                if (File.Exists(@"Data\logo01.jpg"))
Code
                {
Code
                    File.Copy(@"Data\logo01.jpg", logopath, true);
Code
                    File.Copy(@"Data\logo01.jpg", backupdir + @"\logo01.jpg", true);
Code
                }
Code
                RegistryKey rgk_paths = Application.UserAppDataRegistry.CreateSubKey("UsefulPaths");
Code
                rgk_paths.SetValue("usersettingspath", configpath);
Code
                rgk_paths.SetValue("itembankpath", dbdir);
Code
                rgk_paths.SetValue("appdatapath", datapath);
Code
                rgk_paths.SetValue("userdatapath", userpath);
Code
                rgk_paths.SetValue("backuppath", backupdir);
Code
Code
                if (File.Exists(@"config.gzsettings"))
Code
                {
Code
                    Settings settings = new Settings();
Code
                    settings.Load(@"config.gzsettings");
Code
                    settings["userinfofolderpath"] = userpath;
Code
                    settings["appdatapath"] = datapath;
Code
                    settings["ItemBankPath"] = dbdir;
Code
                    settings["examfolderpath"] = exampath;
Code
                    settings["LogoPath"] = logopath;
Code
                    settings["BackgroundImagePath"] = bgpath;
Code
                    settings["BarnerPath"] = bannerpath;
Code
                    using (RegistryKey rgk_settings = Application.UserAppDataRegistry.CreateSubKey("defaultsettings"))
Code
                    {
Code
                        foreach (var key in settings.GetData().Keys)
Code
                        {
Code
                            rgk_settings.SetValue(key, settings[key]);
Code
                        }
Code
                        rgk_settings.Close();
Code
                    }
Code
                    settings.Save(backupdir + @"\config.gzsettings");
Code
                    settings.Save(configpath);
Code
                }
Code
            }
Code
            catch (Exception e)
Code
            {
Code
                throw new ApplicationException("Database creation fault: \n" + e.Message);
Code
            }
Code
        }