Beispiel #1
0
        private static void CopyOldTools(string outerToolsFolderPath, ILongWaitBroker broker)
        {
            //Copy tools to a different folder then Directory.Move if successful.
            string tempOuterToolsFolderPath = string.Concat(outerToolsFolderPath, @"_installing");

            if (Directory.Exists(tempOuterToolsFolderPath))
            {
                DirectoryEx.SafeDelete(tempOuterToolsFolderPath);
                // Not sure this is necessay, but just to be safe
                if (Directory.Exists(tempOuterToolsFolderPath))
                {
                    throw new Exception(Resources.Program_CopyOldTools_Error_copying_external_tools_from_previous_installation);
                }
            }

            // Must create the tools directory to avoid ending up here again next time
            Directory.CreateDirectory(tempOuterToolsFolderPath);

            ToolList  toolList      = Settings.Default.ToolList;
            int       numTools      = toolList.Count;
            const int endValue      = 100;
            int       progressValue = 0;
            // ReSharper disable once UselessBinaryOperation (in case we decide to start at progress>0 for display purposes)
            int increment = (endValue - progressValue) / (numTools + 1);

            foreach (var tool in toolList)
            {
                string toolDirPath = tool.ToolDirPath;
                if (!string.IsNullOrEmpty(toolDirPath) && Directory.Exists(toolDirPath))
                {
                    string foldername = Path.GetFileName(toolDirPath);
                    string newDir     = Path.Combine(outerToolsFolderPath, foldername);
                    string tempNewDir = Path.Combine(tempOuterToolsFolderPath, foldername);
                    if (!Directory.Exists(tempNewDir))
                    {
                        DirectoryEx.DirectoryCopy(toolDirPath, tempNewDir, true);
                    }
                    tool.ToolDirPath          = newDir; // Update the tool to point to its new directory.
                    tool.ArgsCollectorDllPath = tool.ArgsCollectorDllPath.Replace(toolDirPath, newDir);
                }
                if (broker.IsCanceled)
                {
                    // Don't leave around a corrupted directory
                    DirectoryEx.SafeDelete(tempOuterToolsFolderPath);
                    return;
                }

                progressValue       += increment;
                broker.ProgressValue = progressValue;
            }
            Directory.Move(tempOuterToolsFolderPath, outerToolsFolderPath);
            Settings.Default.ToolList = ToolList.CopyTools(toolList);
        }
Beispiel #2
0
        /// <summary>
        /// Copy a zip file's contents to the tools folder and loop through its .properties
        /// files adding the tools to the tools menu.
        /// </summary>
        /// <param name="parent">Parent window for alerts and forms</param>
        /// <param name="fullpath">The full path to the zipped folder containing the tools</param>
        /// <param name="install">Installation function</param>
        public static void InstallZipTool(Control parent, string fullpath, InstallProgram install)
        {
            ToolInstaller.UnzipToolReturnAccumulator result = null;
            var       toolListStart = ToolList.CopyTools(Settings.Default.ToolList);
            Exception xFailure      = null;

            try
            {
                result = ToolInstaller.UnpackZipTool(fullpath, new InstallZipToolHelper(parent, install));
            }
            catch (ToolExecutionException x)
            {
                MessageDlg.ShowException(parent, x);
            }
            catch (Exception x)
            {
                xFailure = x;
            }
            if (xFailure != null)
            {
                MessageDlg.ShowWithException(parent, TextUtil.LineSeparate(String.Format(Resources.ConfigureToolsDlg_UnpackZipTool_Failed_attempting_to_extract_the_tool_from__0_, Path.GetFileName(fullpath)), xFailure.Message), xFailure);
            }

            if (result != null)
            {
                foreach (var message in result.MessagesThrown)
                {
                    MessageDlg.Show(parent, message);
                }
            }
            else
            {
                // If result is Null, then we want to discard changes made to the ToolsList
                Settings.Default.ToolList = toolListStart;
            }
        }
        private void InstallUpdates(ICollection <ToolUpdateInfo> tools)
        {
            if (tools != null && tools.Count != 0 && !TestingDownloadOnly)
            {
                var failedUpdates     = new Dictionary <string, string>();
                var successfulUpdates = new Collection <string>();

                int installCount = 0;
                foreach (var tool in tools)
                {
                    labelOperation.Text =
                        string.Format(Resources.ToolUpdatesDlg_InstallUpdates_Installing_updates_to__0_,
                                      tool._packageName);

                    var  toolList        = ToolList.CopyTools(Settings.Default.ToolList);
                    bool exceptionThrown = false;
                    ToolInstaller.UnzipToolReturnAccumulator result = null;
                    try
                    {
                        result = _updateHelper.UnpackZipTool(tool.FilePath, new ToolInstallUI.InstallZipToolHelper(_parent.InstallProgram));
                    }
                    catch (ToolExecutionException x)
                    {
                        failedUpdates.Add(tool._packageName, x.Message);
                        exceptionThrown = true;
                    }
                    catch (IOException x)
                    {
                        failedUpdates.Add(tool._packageName,
                                          TextUtil.LineSeparate(string.Format(Resources.ConfigureToolsDlg_UnpackZipTool_Failed_attempting_to_extract_the_tool_from__0_,
                                                                              Path.GetFileName(tool.FilePath)), x.Message));
                        exceptionThrown = true;
                    }

                    progressBar.Value = Convert.ToInt32((((((double)++installCount) / tools.Count) * 100) / 2) + 50);

                    if (result == null)
                    {
                        // user cancelled
                        if (!exceptionThrown)
                        {
                            failedUpdates.Add(tool._packageName, Resources.ToolUpdatesDlg_InstallUpdates_User_cancelled_installation);
                        }

                        // reset tool list
                        Settings.Default.ToolList = toolList;
                        continue;
                    }

                    // tool was successfully updated
                    result.MessagesThrown.ForEach(message => MessageDlg.Show(this, message));
                    successfulUpdates.Add(tool._packageName);
                }

                // clean-up
                DirectoryEx.SafeDelete(ToolDir.FullName);

                progressBar.Value = 100;
                DisplayInstallSummary(successfulUpdates, failedUpdates);
            }
        }