Esempio n. 1
0
        private void InstallUpdateFromZip(string strZipPath, HashSet <string> lstFilesToDelete)
        {
            bool blnDoRestart = true;

            // Copy over the archive from the temp directory.
            Log.Info("Extracting downloaded archive into application path: ", strZipPath);
            using (ZipArchive archive = ZipFile.Open(strZipPath, ZipArchiveMode.Read, Encoding.GetEncoding(850)))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    // Skip directories because they already get handled with Directory.CreateDirectory
                    if (entry.FullName.Length > 0 && entry.FullName[entry.FullName.Length - 1] == '/')
                    {
                        continue;
                    }
                    string strLoopPath = Path.Combine(_strAppPath, entry.FullName);
                    try
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(strLoopPath));
                        entry.ExtractToFile(strLoopPath, true);
                        lstFilesToDelete.Remove(strLoopPath.Replace('/', Path.DirectorySeparatorChar));
                    }
                    catch (UnauthorizedAccessException)
                    {
                        MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning"));
                        blnDoRestart = false;
                        break;
                    }
                }
            }
            if (blnDoRestart)
            {
                foreach (string strFileToDelete in lstFilesToDelete)
                {
                    if (File.Exists(strFileToDelete))
                    {
                        File.Delete(strFileToDelete);
                    }
                }
                Utils.RestartApplication(string.Empty);
            }
        }
Esempio n. 2
0
 private void mnuRestart_Click(object sender, EventArgs e)
 {
     Utils.RestartApplication();
 }
Esempio n. 3
0
 private void mnuRestart_Click(object sender, EventArgs e)
 {
     Utils.RestartApplication(GlobalOptions.Language, "Message_Options_Restart");
 }
Esempio n. 4
0
        private void InstallUpdateFromZip(string strZipPath, HashSet <string> lstFilesToDelete)
        {
            bool blnDoRestart = true;

            // Copy over the archive from the temp directory.
            Log.Info("Extracting downloaded archive into application path: ", strZipPath);
            try
            {
                using (ZipArchive archive = ZipFile.Open(strZipPath, ZipArchiveMode.Read, Encoding.GetEncoding(850)))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        // Skip directories because they already get handled with Directory.CreateDirectory
                        if (entry.FullName.Length > 0 && entry.FullName[entry.FullName.Length - 1] == '/')
                        {
                            continue;
                        }
                        string strLoopPath = Path.Combine(_strAppPath, entry.FullName);
                        try
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(strLoopPath));
                            if (File.Exists(strLoopPath))
                            {
                                if (File.Exists(strLoopPath + ".old"))
                                {
                                    File.Delete(strLoopPath + ".old");
                                }
                                File.Move(strLoopPath, strLoopPath + ".old");
                            }
                            entry.ExtractToFile(strLoopPath, false);
                        }
                        catch (IOException)
                        {
                            MessageBox.Show(LanguageManager.GetString("Message_File_Cannot_Be_Accessed", GlobalOptions.Language) + "\n\n" + Path.GetFileName(strLoopPath));
                            blnDoRestart = false;
                            break;
                        }
                        catch (NotSupportedException)
                        {
                            MessageBox.Show(LanguageManager.GetString("Message_File_Cannot_Be_Accessed", GlobalOptions.Language) + "\n\n" + Path.GetFileName(strLoopPath));
                            blnDoRestart = false;
                            break;
                        }
                        catch (UnauthorizedAccessException)
                        {
                            MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning", GlobalOptions.Language));
                            blnDoRestart = false;
                            break;
                        }
                        lstFilesToDelete.Remove(strLoopPath.Replace('/', Path.DirectorySeparatorChar));
                    }
                }
            }
            catch (IOException)
            {
                MessageBox.Show(LanguageManager.GetString("Message_File_Cannot_Be_Accessed", GlobalOptions.Language) + "\n\n" + strZipPath);
                blnDoRestart = false;
            }
            catch (NotSupportedException)
            {
                MessageBox.Show(LanguageManager.GetString("Message_File_Cannot_Be_Accessed", GlobalOptions.Language) + "\n\n" + strZipPath);
                blnDoRestart = false;
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning", GlobalOptions.Language));
                blnDoRestart = false;
            }
            if (blnDoRestart)
            {
                foreach (string strFileToDelete in lstFilesToDelete)
                {
                    if (File.Exists(strFileToDelete))
                    {
                        File.Delete(strFileToDelete);
                    }
                }
                Utils.RestartApplication(GlobalOptions.Language, string.Empty);
            }
            else
            {
                foreach (string strBackupFileName in Directory.GetFiles(_strAppPath, "*.old", SearchOption.AllDirectories))
                {
                    try
                    {
                        File.Move(strBackupFileName, strBackupFileName.Substring(0, strBackupFileName.Length - 4));
                    }
                    catch (IOException)
                    {
                    }
                    catch (NotSupportedException)
                    {
                    }
                    catch (UnauthorizedAccessException)
                    {
                    }
                }
            }
        }
Esempio n. 5
0
        private void cmdRestart_Click(object sender, EventArgs e)
        {
            Log.Info("cmdRestart_Click");
            if (Directory.Exists(_strAppPath) && File.Exists(_strTempPath))
            {
                Cursor             = Cursors.WaitCursor;
                cmdUpdate.Enabled  = false;
                cmdRestart.Enabled = false;
                //Create a backup file in the temp directory.
                string strBackupZipPath = Path.Combine(Path.GetTempPath(), "chummer" + CurrentVersion + ".zip");
                Log.Info("Creating archive from application path: ", _strAppPath);
                try
                {
                    if (!File.Exists(strBackupZipPath))
                    {
                        ZipFile.CreateFromDirectory(_strAppPath, strBackupZipPath, CompressionLevel.Fastest, true);
                    }
                    // Delete the old Chummer5 executables, libraries, and other files whose current versions are in use, then rename the current versions.
                    foreach (string strLoopExeName in Directory.GetFiles(_strAppPath, "*.exe", SearchOption.AllDirectories))
                    {
                        if (File.Exists(strLoopExeName + ".old"))
                        {
                            File.Delete(strLoopExeName + ".old");
                        }
                        File.Move(strLoopExeName, strLoopExeName + ".old");
                    }
                    foreach (string strLoopDllName in Directory.GetFiles(_strAppPath, "*.dll", SearchOption.AllDirectories))
                    {
                        if (File.Exists(strLoopDllName + ".old"))
                        {
                            File.Delete(strLoopDllName + ".old");
                        }
                        File.Move(strLoopDllName, strLoopDllName + ".old");
                    }
                    foreach (string strLoopPdbName in Directory.GetFiles(_strAppPath, "*.pdb", SearchOption.AllDirectories))
                    {
                        if (File.Exists(strLoopPdbName + ".old"))
                        {
                            File.Delete(strLoopPdbName + ".old");
                        }
                        File.Move(strLoopPdbName, strLoopPdbName + ".old");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning"));
                    Cursor = Cursors.Default;
                    return;
                }

                bool             blnDoRestart        = true;
                HashSet <string> lstFilesToDelete    = new HashSet <string>(Directory.GetFiles(_strAppPath, "*", SearchOption.AllDirectories));
                HashSet <string> lstFilesToNotDelete = new HashSet <string>();
                foreach (string strFileToDelete in lstFilesToDelete)
                {
                    string strFileName       = Path.GetFileName(strFileToDelete);
                    string strFilePath       = Path.GetDirectoryName(strFileToDelete).TrimStart(_strAppPath);
                    int    intSeparatorIndex = strFilePath.LastIndexOf(Path.DirectorySeparatorChar);
                    string strTopLevelFolder = intSeparatorIndex != -1 ? strFilePath.Substring(intSeparatorIndex + 1) : string.Empty;
                    if (strFileName.EndsWith(".old") ||
                        strFileName.StartsWith("custom") ||
                        strFileName.StartsWith("override") ||
                        strFileName.StartsWith("amend") ||
                        strFilePath.Contains("customdata") ||
                        (strFilePath.Contains("sheets") && strTopLevelFolder != "de" && strTopLevelFolder != "fr" && strTopLevelFolder != "jp" && strTopLevelFolder != "zh") ||
                        (strTopLevelFolder == "lang" && strFileName != "de.xml" && strFileName != "fr.xml" && strFileName != "jp.xml" && strFileName != "zh.xml" && strFileName != "de_data.xml" && strFileName != "fr_data.xml" && strFileName != "jp_data.xml" && strFileName != "zh_data.xml"))
                    {
                        lstFilesToNotDelete.Add(strFileToDelete);
                    }
                }
                lstFilesToDelete.RemoveWhere(x => lstFilesToNotDelete.Contains(x));

                // Copy over the archive from the temp directory.
                Log.Info("Extracting downloaded archive into application path: ", _strTempPath);
                using (ZipArchive archive = ZipFile.Open(_strTempPath, ZipArchiveMode.Read, Encoding.GetEncoding(850)))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        // Skip directories because they already get handled with Directory.CreateDirectory
                        if (entry.FullName.Length > 0 && entry.FullName[entry.FullName.Length - 1] == '/')
                        {
                            continue;
                        }
                        string strLoopPath = Path.Combine(_strAppPath, entry.FullName);
                        try
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(strLoopPath));
                            entry.ExtractToFile(strLoopPath, true);
                            lstFilesToDelete.Remove(strLoopPath);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            MessageBox.Show(LanguageManager.GetString("Message_Insufficient_Permissions_Warning"));
                            blnDoRestart = false;
                            break;
                        }
                    }
                }
                if (blnDoRestart)
                {
                    foreach (string strFileToDelete in lstFilesToDelete)
                    {
                        if (File.Exists(strFileToDelete))
                        {
                            File.Delete(strFileToDelete);
                        }
                    }
                    Utils.RestartApplication(string.Empty);
                }
            }
        }