目录未在安装程序自定义操作期间创建,vs2010安装程序 [英] Directories not created during installer custom action, vs2010 installer

查看:77
本文介绍了目录未在安装程序自定义操作期间创建,vs2010安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天先生/ ma's



请尝试为vs 2010安装程序编写自定义操作库。在自定义操作的Install事件中,我尝试将某些文件(其中包括sqlite数据库)复制到AppData \ Local \ MySoftware等位置,以及My Document文件夹中的某些文件。我知道我应该使用VS2010安装程序包的目标机器上的文件系统属性并添加这些文件夹,但我需要遍历一些文件列表并将它们添加到我的文档和MySoftware文件夹中我想将每个文件的目录存储到注册表中。



我创建了一个继承自Installer Class的新类并覆盖Install事件,然后将下面的文件放入代码但没有创建任何文件夹,没有一个值被写入注册表并且没有抛出错误,包已成功安装但是没有创建那些目录,文件夹和注册表路径。



我尝试从主窗体的Load事件调用Install库(我编写的自定义操作libraray),它工作,所有注册表和文件夹都被创建,表明我的代码没有任何问题。



请帮帮我。



我的尝试:



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.

What I have tried:

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");

                        if (File.Exists(file))

                        {

                            int i = 1;

                            do

                            {

                                file = string.Format("{0}\\config_old {1}.gzsettings", datapath, i);

                                i++;

                            }

                            while (File.Exists(file));

                        }


                        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);


                if (File.Exists(@"config.gzsettings"))

                {

                    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);

            }

        }</code>

推荐答案

任何理由应用程序运行时,您不创建文件夹?我更喜欢应用程序自动修复文件夹和文件,因为您不知道用户在应用程序运行后以及应用程序未处于活动状态时将执行的操作。
Any reason why you don't create the folders when the app runs? I prefer the app to "auto-repair" folders and files as you don't know what the user will do after the app runs and when the app is not active.


这篇关于目录未在安装程序自定义操作期间创建,vs2010安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆