Ejemplo n.º 1
0
        // 创建数据目录,并复制进基本内容
        int CreateNewDataDir(string strDataDir,
            out string strError)
        {
            strError = "";

            PathUtil.CreateDirIfNeed(strDataDir);

            Debug.Assert(this.CopyFiles != null, "");

            CopyFilesEventArgs e = new CopyFilesEventArgs();
            e.Action = "data";
            e.DataDir = strDataDir;
            this.CopyFiles(this, e);
            if (string.IsNullOrEmpty(e.ErrorInfo) == false)
            {
                strError = "拷贝文件到数据目录 '" + strDataDir + "' 时发生错误:" + e.ErrorInfo;
                return -1;
            }

            return 0;
        }
Ejemplo n.º 2
0
        // 创建程序目录,并复制进基本内容
        // parameters:
        //      strDataDir  要写入 start.xml 中的数据目录路径
        int CreateNewAppDir(string strAppDir,
            string strDataDir,
            out string strError)
        {
            strError = "";

            PathUtil.CreateDirIfNeed(strAppDir);

            Debug.Assert(this.CopyFiles != null, "");

            CopyFilesEventArgs e = new CopyFilesEventArgs();
            e.Action = "app";
            e.DataDir = strAppDir;
            this.CopyFiles(this, e);
            if (string.IsNullOrEmpty(e.ErrorInfo) == false)
            {
                strError = "拷贝文件到程序目录 '" + strAppDir + "' 时发生错误:" + e.ErrorInfo;
                return -1;
            }

            // 修改 start.xml
            int nRet = CreateStartXml(Path.Combine(strAppDir, "start.xml"),
                        strDataDir,
                        out strError);
            if (nRet == -1)
                return -1;

            return 0;
        }
Ejemplo n.º 3
0
        // 兑现修改。
        // 创建数据目录。创建或者修改library.xml文件
        int DoModify(out string strError)
        {
            strError = "";
            int nRet = 0;

            for (int i = 0; i < this.listView_instance.Items.Count; i++)
            {
                ListViewItem item = this.listView_instance.Items[i];
                LineInfo info = (LineInfo)item.Tag;
                string strDataDir = ListViewUtil.GetItemText(item, COLUMN_DATADIR);
                string strInstanceName = ListViewUtil.GetItemText(item, COLUMN_NAME);
                string strBindings = ListViewUtil.GetItemText(item, COLUMN_BINDINGS);

                if (String.IsNullOrEmpty(strDataDir) == true)
                {
                    strError = "第 "+(i+1).ToString()+" 行的数据目录尚未设置";
                    return -1;
                }

                if (String.IsNullOrEmpty(strBindings) == true)
                {
                    strError = "第 " + (i + 1).ToString() + " 行的协议绑定尚未设置";
                    return -1;
                }

                if (info.Changed == false && info.Upgrade == false
                    && info.UpdateCfgsDir == false)
                    goto CONTINUE;

                // 探测数据目录,是否已经存在数据,是不是属于升级情形
                // return:
                //      -1  error
                //      0   数据目录不存在
                //      1   数据目录存在,但是xml文件不存在
                //      2   xml文件已经存在
                nRet = LibraryInstallHelper.DetectDataDir(strDataDir,
            out strError);
                if (nRet == -1)
                    return -1;

                if (nRet == 2)
                {
                    // 进行升级检查

                    // 检查xml文件的版本。看看是否有必要提示升级
                    // return:
                    //      -1  error
                    //      0   没有version,即为V1格式
                    //      1   < 2.0
                    //      2   == 2.0
                    //      3   > 2.0
                    nRet = DetectXmlFileVersion(strDataDir,
            out strError);
                    if (nRet == -1)
                        return -1;
                    if (nRet < 2)
                    {
                        // 提示升级安装
                        // 从以前的rmsws数据目录升级
                        string strText = "数据目录 '" + strDataDir + "' 中已经存在以前的 V1 图书馆应用服务器版本遗留下来的数据文件。\r\n\r\n确实要利用这个数据目录来进行升级安装么?\r\n(注意:如果利用以前dp2libraryws的数据目录来进行升级安装,则必须先行卸载dp2libraryws,以避免它和(正在安装的)dp2Library同时运行引起冲突)\r\n\r\n(是)继续进行升级安装 (否)暂停安装,以重新指定数据目录";
                        DialogResult result = MessageBox.Show(
                            this,
            strText,
        "dp2Library 实例管理",
            MessageBoxButtons.YesNo,
            MessageBoxIcon.Question,
            MessageBoxDefaultButton.Button1);
                        /*
                        if (result == DialogResult.Cancel)
                        {
                            strError = "用户放弃指定数据目录。安装未完成。";
                            return -1;
                        }
                         * */
                        if (result == DialogResult.No)
                        {
                            strError = "请利用“修改”按钮重新指定实例 '" + item.Text + "' 的数据目录";
                            return -1;
                        }

                        // 刷新cfgs目录

                        info.Upgrade = true;
                    }

                    // 覆盖数据目录中的templates子目录
                    // parameters:
                    //      strRootDir  根目录
                    //      strDataDir    数据目录
                    nRet = OverwriteTemplates(
                        strDataDir,
                        out strError);
                    if (nRet == -1)
                    {
                        // 报错,但是不停止安装
                        MessageBox.Show(this,
                            strError);
                    }

                }
                else
                {
                    // 需要进行最新安装
                    nRet = CreateNewDataDir(strDataDir,
    out strError);
                    if (nRet == -1)
                        return -1;

                    this.NewInstanceNames.Add(strInstanceName);
                }


                // 兑现修改
                if (info.Changed == true
                    || info.Upgrade == true)
                {
                    // 保存信息到library.xml文件中
                    // return:
                    //      -1  error
                    //      0   succeed
                    nRet = info.SaveToXml(strDataDir,
                        out strError);
                    if (nRet == -1)
                        return -1;

                    if (info.Upgrade == true)
                    {
                        nRet = UpdateXmlFileVersion(strDataDir,
                            out strError);
                        if (nRet == -1)
                        {
                            strError = "刷新database.xml文件<version>元素的时候出错: " + strError;
                            return -1;
                        }


                        // 覆盖数据目录中的cfgs子目录

                        // 1) 先备份原来的cfgs子目录
                        string strSourceDir = PathUtil.MergePath(strDataDir, "cfgs");
                        string strTargetDir = PathUtil.MergePath(strDataDir, "v1_cfgs_backup");
                        if (Directory.Exists(strTargetDir) == false)
                        {
                            MessageBox.Show(this,
            "安装程序将升级位于数据目录 '" + strSourceDir + "' 中的配置文件。原有文件将自动备份在目录 '" + strTargetDir + "' 中。");
                            nRet = PathUtil.CopyDirectory(strSourceDir,
            strTargetDir,
            true,
            out strError);
                            if (nRet == -1)
                            {
                                strError = "备份目录 '" + strSourceDir + "' 到 '" + strTargetDir + "' 时发生错误:" + strError;
                                MessageBox.Show(this,
                                    strError);
                            }
                        }

                        if (string.IsNullOrEmpty(this.SourceDir) == false)
                        {
                            // 兼容以前的 sourceDir 用法
                            Debug.Assert(String.IsNullOrEmpty(this.SourceDir) == false, "");
                            string strTempDataDir = PathUtil.MergePath(this.SourceDir, "temp");

                            strSourceDir = PathUtil.MergePath(strTempDataDir, "cfgs");
                            strTargetDir = PathUtil.MergePath(strDataDir, "cfgs");
                        REDO:
                            try
                            {
                                nRet = PathUtil.CopyDirectory(strSourceDir,
                    strTargetDir,
                    true,
                    out strError);
                            }
                            catch (Exception ex)
                            {
                                strError = "拷贝目录 '" + strSourceDir + "' 到配置文件目录 '" + strTargetDir + "' 发生错误:" + ex.Message;
                                DialogResult temp_result = MessageBox.Show(this, // ForegroundWindow.Instance,
    strError + "\r\n\r\n是否重试?",
    "dp2Library 实例管理",
    MessageBoxButtons.RetryCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                                if (temp_result == DialogResult.Retry)
                                    goto REDO;
                                throw new InstallException(strError);
                            }

                            if (nRet == -1)
                            {
                                strError = "拷贝目录 '" + strSourceDir + "' 到配置文件目录 '" + strTargetDir + "' 发生错误:" + strError;
                                throw new InstallException(strError);
                            }
                        }
                        else
                        {
                            // 新的方法,直接从 .zip 文件展开
                            Debug.Assert(this.CopyFiles != null, "");

                            strTargetDir = PathUtil.MergePath(strDataDir, "cfgs");
                            CopyFilesEventArgs e = new CopyFilesEventArgs();
                            e.Action = "cfgs";
                            e.DataDir = strDataDir;
                            this.CopyFiles(this, e);
                            if (string.IsNullOrEmpty(e.ErrorInfo) == false)
                            {
                                strError = "拷贝目录 cfgs 到配置文件目录 '" + strTargetDir + "' 时发生错误:" + strError;
                                throw new InstallException(strError);
                            }
                        }

                        info.UpdateCfgsDir = false; // 避免重复做
                    }

                    /*
                    // 在注册表中写入instance信息
                    InstallHelper.SetInstanceInfo(
                        "dp2Library",
                        i,
                        strInstanceName,
                        strDataDir,
                        strBindings.Split(new char []{';'}),
                        info.CertificateSN);
                     * */

                    info.Changed = false;
                    info.Upgrade = false;
                }

                // 注:因为有了 dp2Installer 的自动升级功能,所以这个功能似乎没有存在的必要了
                // 2011/7/3
                if (info.UpdateCfgsDir == true)
                {
                    // 覆盖数据目录中的cfgs子目录

                    if (string.IsNullOrEmpty(this.SourceDir) == false)
                    {
                        // 兼容以前的 this.SourceDir 用法

                        Debug.Assert(String.IsNullOrEmpty(this.SourceDir) == false, "");
                        string strTempDataDir = PathUtil.MergePath(this.SourceDir, "temp");

                        string strSourceDir = PathUtil.MergePath(strTempDataDir, "cfgs");
                        string strTargetDir = PathUtil.MergePath(strDataDir, "cfgs");
                    REDO:
                        try
                        {
                            nRet = PathUtil.CopyDirectory(strSourceDir,
        strTargetDir,
        true,
        out strError);
                        }
                        catch (Exception ex)
                        {
                            strError = "拷贝目录 '" + strSourceDir + "' 到配置文件目录 '" + strTargetDir + "' 发生错误:" + ex.Message;
                            DialogResult temp_result = MessageBox.Show(this, //ForegroundWindow.Instance,
    strError + "\r\n\r\n是否重试?",
    "dp2Library 实例管理",
    MessageBoxButtons.RetryCancel,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1);
                            if (temp_result == DialogResult.Retry)
                                goto REDO;
                            throw new InstallException(strError);
                        }

                        if (nRet == -1)
                        {
                            strError = "拷贝目录 '" + strSourceDir + "' 到配置文件目录 '" + strTargetDir + "' 发生错误:" + strError;
                            throw new InstallException(strError);
                        }
                    }
                    else
                    {
                        // 新的用法,直接从 .zip 文件中展开
                        Debug.Assert(this.CopyFiles != null, "");

                        string strTargetDir = PathUtil.MergePath(strDataDir, "cfgs");
                        CopyFilesEventArgs e = new CopyFilesEventArgs();
                        e.Action = "cfgs";
                        e.DataDir = strDataDir;
                        this.CopyFiles(this, e);
                        if (string.IsNullOrEmpty(e.ErrorInfo) == false)
                        {
                            strError = "拷贝目录 cfgs 到配置文件目录 '" + strTargetDir + "' 时发生错误:" + strError;
                            throw new InstallException(strError);
                        }
                    }
                }

                CONTINUE:
                // 在注册表中写入instance信息
                // 因为可能插入或者删除任意实例,那么注册表事项需要全部重写
                InstallHelper.SetInstanceInfo(
                    "dp2Library",
                    i,
                    strInstanceName,
                    strDataDir,
                    strBindings.Split(new char[] { ';' }),
                    info.CertificateSN,
                    info.SerialNumber);
            }

            // 删除注册表中多余的instance信息
            for (int i = this.listView_instance.Items.Count; ; i++)
            {
                // 删除Instance信息
                // return:
                //      false   instance没有找到
                //      true    找到,并已经删除
                bool bRet = InstallHelper.DeleteInstanceInfo(
                    "dp2Library",
                    i);
                if (bRet == false)
                    break;
            }

            return 0;
        }
Ejemplo n.º 4
0
        // 创建数据目录,并复制进基本内容
        int CreateNewDataDir(string strDataDir,
            out string strError)
        {
            strError = "";

            PathUtil.CreateDirIfNeed(strDataDir);

            if (string.IsNullOrEmpty(this.SourceDir) == false)
            {
                // 兼容以前的 this.SourceDir 用法

                // 要求在temp内准备要安装的数据文件(初次安装而不是升级安装)
                Debug.Assert(String.IsNullOrEmpty(this.SourceDir) == false, "");
                string strTempDataDir = PathUtil.MergePath(this.SourceDir, "temp");

                int nRet = PathUtil.CopyDirectory(strTempDataDir,
        strDataDir,
        true,
        out strError);
                if (nRet == -1)
                {
                    strError = "拷贝临时目录 '" + strTempDataDir + "' 到数据目录 '" + strDataDir + "' 时发生错误:" + strError;
                    return -1;
                }
            }
            else
            {
                // 新的用法
                Debug.Assert(this.CopyFiles != null, "");

                CopyFilesEventArgs e = new CopyFilesEventArgs();
                e.Action = "cfgs,templates,other";
                e.DataDir = strDataDir;
                this.CopyFiles(this, e);
                if (string.IsNullOrEmpty(e.ErrorInfo) == false)
                {
                    strError = "拷贝到配置文件目录 '" + strDataDir + "' 时发生错误:" + strError;
                    return -1;
                }
            }

            return 0;
        }
Ejemplo n.º 5
0
        // 覆盖数据目录中的templates子目录
        // parameters:
        //      strRootDir  根目录
        //      strDataDir    数据目录
        public int OverwriteTemplates(string strDataDir,
            out string strError)
        {
            strError = "";

            int nRet = 0;

            if (string.IsNullOrEmpty(this.SourceDir) == false)
            {
                // 兼容以前的 this.SourceDir 用法

                Debug.Assert(String.IsNullOrEmpty(this.SourceDir) == false, "");

                string strTemplatesSourceDir = PathUtil.MergePath(this.SourceDir, "temp\\templates");
                string strTemplatesTargetDir = PathUtil.MergePath(strDataDir, "templates");

                PathUtil.CreateDirIfNeed(strTemplatesTargetDir);

                nRet = PathUtil.CopyDirectory(strTemplatesSourceDir,
                    strTemplatesTargetDir,
                    false,  // 拷贝前不删除原来的目录
                    out strError);
                if (nRet == -1)
                {
                    strError = "拷贝临时模板目录 '" + strTemplatesSourceDir + "' 到数据目录之模板目录 '" + strTemplatesTargetDir + "' 时发生错误:" + strError;
                    // throw new InstallException(strError);
                    return -1;
                }
            }
            else
            {
                // 新的用法
                Debug.Assert(this.CopyFiles != null, "");

                string strTargetDir = PathUtil.MergePath(strDataDir, "templates");
                CopyFilesEventArgs e = new CopyFilesEventArgs();
                e.Action = "templates";
                e.DataDir = strDataDir;
                this.CopyFiles(this, e);
                if (string.IsNullOrEmpty(e.ErrorInfo) == false)
                {
                    strError = "拷贝目录 templates 到配置文件目录 '" + strTargetDir + "' 时发生错误:" + strError;
                    return -1;
                }
            }

            return 0;
        }
Ejemplo n.º 6
0
        void dlg_dp2OPAC_CopyFiles(object sender, CopyFilesEventArgs e)
        {
            string strError = "";
            int nRet = 0;

            Debug.Assert(e.Action == "app" || e.Action == "data", "");

            if (e.Action == "app")
            {
                string strZipFileName = Path.Combine(this.DataDir, "opac_app.zip");

                // 更新可执行目录
                // return:
                //      -1  出错
                //      0   没有必要刷新
                //      1   已经刷新
                nRet = RefreshBinFiles(
                    false,
                    strZipFileName,
                    e.DataDir,
                    null,   // 包括了 web.config
                    out strError);
                if (nRet == -1)
                {
                    e.ErrorInfo = strError;
                    return;
                }

#if NO
                // 从 opac_style.zip 中展开部分目录内容
                string strTargetPath = Path.Combine(e.DataDir, "style");
                if (Directory.Exists(strTargetPath) == true)
                {
                    strZipFileName = Path.Combine(this.DataDir, "opac_style.zip");

                    nRet = dp2OPAC_extractDir(
                        false,
                        strZipFileName,
                        strTargetPath,
                        out strError);
                    if (nRet == -1)
                    {
                        e.ErrorInfo = strError;
                        return;
                    }
                }
#endif
            }

            if (e.Action == "data")
            {
                string strZipFileName = Path.Combine(this.DataDir, "opac_data.zip");
                try
                {
                    using (ZipFile zip = ZipFile.Read(strZipFileName))
                    {
                        for (int i = 0; i < zip.Count; i++)
                        {
                            ZipEntry e1 = zip[i];

                            string strPart = GetSubPath(e1.FileName);
                            string strFullPath = Path.Combine(e.DataDir, strPart);

                            e1.FileName = strPart;

                            e1.Extract(e.DataDir, ExtractExistingFileAction.OverwriteSilently);
                        }
                    }
                }
                catch (Exception ex)
                {
                    strError = ex.Message;
                    e.ErrorInfo = strError;
                    return;
                }

                // 从 opac_style.zip 中展开部分目录内容
                string strTargetPath = Path.Combine(e.DataDir, "style");
                if (Directory.Exists(strTargetPath) == true)
                {
                    strZipFileName = Path.Combine(this.DataDir, "opac_style.zip");

                    nRet = dp2OPAC_extractDir(
                        false,
                        strZipFileName,
                        strTargetPath,
                        true,   // 需要避开 .css.macro 文件的 .css 文件
                        out strError);
                    if (nRet == -1)
                    {
                        e.ErrorInfo = strError;
                        return;
                    }
                }
            }

        }
Ejemplo n.º 7
0
 void dlg_dp2Library_CopyFiles(object sender, CopyFilesEventArgs e)
 {
     string strError = "";
     int nRet = dp2Library_extractPartDir(
         e.DataDir,
         e.Action,
         out strError);
     if (nRet == -1)
     {
         e.ErrorInfo = strError;
         return;
     }
 }