예제 #1
0
        //Added by daRedLoCo
        /// <summary>
        /// Extracts a ZipArchive to a destination (with overwrite functionality and ZipSettings inside the archive)
        /// </summary>
        /// <param name="archive">The archive to unpack</param>
        /// <param name="destinationDirectoryName">The destination directory</param>
        /// <param name="overwrite">If true, it will overwrite the content inside the destination directory</param>
        public static bool ExtractWithSettings(this ZipArchive archive, string destinationDirectoryName, bool overwrite)
        {
            ZipSettings settings             = null;
            bool        extractionSuccessful = true;

            if (archive.GetEntry("zipsettings.json") != null)
            {
                settings = ZipSettings.FromStream(archive.GetEntry("zipsettings.json").Open());
            }
            if (settings == null || settings.Subfolders.Count < 1)
            {
                return(ExtractToDirectory(archive, destinationDirectoryName, overwrite));
            }
            Uninstaller uninstaller = new Uninstaller(destinationDirectoryName);

            foreach (ZipArchiveEntry file in archive.Entries)
            {
                string completeFileName = Path.Combine(destinationDirectoryName, settings.GetSubfolder(file.FullName), file.FullName);
                string directory        = Path.GetDirectoryName(completeFileName);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                if (!string.IsNullOrEmpty(file.Name) && file.Name != "zipsettings.json")
                {
                    while (!Utils.CanBeWrittenTo(completeFileName))
                    {
                        if (DialogResult.Cancel == MessageBox.Show($"The file '{completeFileName}' is locked or in use and can't be overwritten! Please close the process thats blocking it and press OK or press CANCEL to stop the installing process.", "Warning!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning))
                        {
                            MessageBox.Show("Can't progress with the installation!", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            extractionSuccessful = false;
                            break;
                        }
                    }
                    if (!extractionSuccessful)
                    {
                        break;
                    }
                    file.ExtractToFile(completeFileName, overwrite);
                    uninstaller.files.Add(completeFileName);
                }
            }
            if (Settings.Uninstall)
            {
                uninstaller.GenerateFile();
            }


            if (!extractionSuccessful)
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Unpacks the files from downloadedfiles
        /// </summary>
        /// <param name="downloadedfiles">The locations of the downloaded files</param>
        async void UnzipInstalledData(string[] downloadedfiles)
        {
            if (downloadedfiles.Length == 0)
            {
                _window.WriteLog("No files downloaded!");
                return;
            }

            bool wasSuccess = true;

            if (IsUpdate(new FileInfo(downloadedfiles[0]).Directory.FullName))
            {
                _window.WriteLog("Deleting old files from project");
                Uninstaller.DoUninstall(new FileInfo(downloadedfiles[0]).Directory.FullName);
            }

            _window.WriteLog("Unpack zip archives...");
            _window.prog_loading.IsIndeterminate = true;
            await Task.Run(() => {
                foreach (string fname in downloadedfiles)
                {
                    FileInfo fi = new FileInfo(fname);
                    if (fi.Extension == ".zip")
                    {
                        using (FileStream fs = new FileStream(fname, FileMode.Open))
                        {
                            using (ZipArchive archive = new ZipArchive(fs))
                            {
                                wasSuccess = ZipArchiveExtensions.ExtractWithSettings(archive, fi.DirectoryName, true);
                            }
                        }
                        File.Delete(fname);
                    }
                }
            });

            if (!wasSuccess)
            {
                Uninstaller.DoUninstall(new FileInfo(downloadedfiles[0]).DirectoryName);
                _window.WriteLog("There was an error while extracting the archive!");
            }
            else
            {
                _window.WriteLog("Installation complete!");
            }
            _window.prog_loading.IsIndeterminate = false;
            _window.bt_install.IsEnabled         = true;
        }
예제 #3
0
        private void UninstallClicked(object sender, RoutedEventArgs e)
        {
            if (System.Windows.Forms.DialogResult.Yes != System.Windows.Forms.MessageBox.Show("Do you really want to uninstall " + Settings.Project + "?", "Are you sure?", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question))
            {
                return;
            }

            using (System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog())
            {
                fbd.Description = "Choose the installation directory:";
                var result = fbd.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    if (!Uninstaller.DoUninstall(fbd.SelectedPath))
                    {
                        MessageBox.Show("Couldn't uninstall the software, read the log for more informations!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    else
                    {
                        WriteLog("Software was uninstalled successfuly!");
                    }
                }
            }
        }