Esempio n. 1
0
        private void OnUnpack(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBoxResult.No;

            if (!ValidPathTest() || !ValidPathTest2(false))
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to unpack localizations from the current Terraria executable?", "Unpack Localizations", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                LocalizationPacker.Unpack();
                result = TriggerMessageBox.Show(this, MessageIcon.Info, "Localizations successfully unpacked! Would you like to open the output folder?", "Localizations Unpacked", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    Process.Start(LocalizationPacker.OutputDirectory);
                }
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while unpacking localizations! Would you like to see the error?", "Unpack Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }
Esempio n. 2
0
        private void OnRestore(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest(false))
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to restore the current Terraria executable to its backup?", "Restore Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (!File.Exists(LocalizationPacker.BackupPath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Warning, "Could not find Terraria backup!", "Missing Backup");
                return;
            }
            try {
                LocalizationPacker.Restore();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored!", "Terraria Restored");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while restoring Terraria! Would you like to see the error?", "Restore Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }
Esempio n. 3
0
        //--------------------------------
        #region Packing

        private void OnRepack(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest() || !ValidPathTest2(true))
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to repack localizations into the current Terraria executable?", "Repack Localizations", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                bool filesFound = LocalizationPacker.Repack();
                if (filesFound)
                {
                    TriggerMessageBox.Show(this, MessageIcon.Info, "Localizations successfully repacked!", "Localizations Repacked");
                }
                else
                {
                    TriggerMessageBox.Show(this, MessageIcon.Info, "No localization files with the correct names were found in the Repack folder!", "No Localizations");
                }
            }
            catch (Exception ex) {
                // Automatic Restore:
                bool restored     = false;             // assigned later, but unused
                bool needsRestore = false;
                if (!File.Exists(LocalizationPacker.ExePath))
                {
                    needsRestore = true;                     // File doesn't exist anymore? Who knows, it could happen
                }
                else
                {
                    try {
                        // file may still be temporarily in-use, wait a short period of time
                        //  (about the same as spent after initial write)
                        Thread.Sleep(400);
                        // When writing an assembly fails, typically the resulting size is zero bytes.
                        // i.e. one time this happens is when resolving references fails.
                        // Zero bytes means automatic restore-from-backup
                        FileInfo exeInfo = new FileInfo(LocalizationPacker.ExePath);
                        needsRestore = (exeInfo.Length == 0);
                    }
                    catch (Exception ex) {
                        // file may still be in-use... wait a bit longer in the future?
                    }
                }
                if (needsRestore && File.Exists(LocalizationPacker.BackupPath))
                {
                    try {
                        LocalizationPacker.Restore();
                        restored = true;
                    }
                    catch (Exception ex) {
                        // No harm done if we wait for the user to restore later.
                    }
                }
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while repacking localizations! Would you like to see the error?", "Repack Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }