Exemplo n.º 1
0
        private void RepackerThread()
        {
            Invoke((Action)delegate { ChangeRepackState("Deleting old backups..."); });
            // Prepare directories
            string rootDir = Path.Combine(Program.WzManager.BaseDir, "HaCreator");
            string backupDir = Path.Combine(rootDir, "Backup");
            string orgBackupDir = Path.Combine(rootDir, "Original");
            string XMLDir = Path.Combine(rootDir, "XML");
            try
            {
                if (!Directory.Exists(backupDir))
                    Directory.CreateDirectory(backupDir);
                if (!Directory.Exists(orgBackupDir))
                    Directory.CreateDirectory(orgBackupDir);
                if (!Directory.Exists(XMLDir))
                    Directory.CreateDirectory(XMLDir);
                foreach (FileInfo fi in new DirectoryInfo(backupDir).GetFiles())
                {
                    fi.Delete();
                }
            }
            catch (Exception e)
            {
                ShowErrorMessageThreadSafe(e, "backup files");
                return;
            }

            // Save XMLs
            // We have to save XMLs first, otherwise the WzImages will already be disposed when we reach this code
            Invoke((Action)delegate { ChangeRepackState("Saving XMLs..."); });
            foreach (WzImage img in Program.WzManager.updatedImages)
            {
                try
                {
                    string xmlPath = Path.Combine(XMLDir, img.FullPath);
                    string xmlPathDir = Path.GetDirectoryName(xmlPath);
                    if (!Directory.Exists(xmlPathDir))
                        Directory.CreateDirectory(xmlPathDir);
                    WzClassicXmlSerializer xmlSer = new WzClassicXmlSerializer(0, LineBreak.None, false);
                    xmlSer.SerializeImage(img, xmlPath);
                }
                catch (Exception e)
                {
                    ShowErrorMessageThreadSafe(e, "XMLs");
                    return;
                }
            }

            // Save WZ Files
            foreach (WzFile wzf in toRepack)
            {
                Invoke((Action)delegate { ChangeRepackState("Saving " + wzf.Name + "..."); });
                string orgFile = wzf.FilePath;
                string tmpFile = orgFile + "$tmp";
                try
                {
                    wzf.SaveToDisk(tmpFile);
                    wzf.Dispose();
                    string buPath = Path.Combine(orgBackupDir, Path.GetFileName(orgFile));
                    // Try to backup to /Originals/ First, if there is already a file there, we are not original, so just backup to /Backup/
                    if (File.Exists(buPath))
                    {
                        buPath = Path.Combine(backupDir, Path.GetFileName(orgFile));
                    }
                    File.Move(orgFile, buPath);
                    File.Move(tmpFile, orgFile);
                }
                catch (Exception e)
                {
                    ShowErrorMessageThreadSafe(e, wzf.Name);
                    return;
                }
            }

            Invoke((Action)delegate { ChangeRepackState("Finished"); FinishSuccess();});
        }
Exemplo n.º 2
0
 private void xMLToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog() { Title = "Choose the files you wish to export", Filter = "WZ Files(*.wz)|*.wz", Multiselect = true };
     if (dialog.ShowDialog() != DialogResult.OK) return;
     FolderBrowserDialog folderDialog = new FolderBrowserDialog() { Description = "Select where to output the files to" };
     if (folderDialog.ShowDialog() != DialogResult.OK) return;
     WzClassicXmlSerializer serializer = new WzClassicXmlSerializer(UserSettings.Indentation, UserSettings.LineBreakType, false);
     threadDone = false;
     new Thread(new ParameterizedThreadStart(RunWzFilesExtraction)).Start((object)new object[] { dialog.FileNames, folderDialog.SelectedPath, encryptionBox.SelectedIndex, serializer });
     new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
 }
Exemplo n.º 3
0
 private void classicToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string outPath = GetOutputDirectory();
     if (outPath == "") return;
     List<WzDirectory> dirs = new List<WzDirectory>();
     List<WzImage> imgs = new List<WzImage>();
     foreach (WzNode node in MainPanel.DataTree.SelectedNodes)
     {
         if (node.Tag is WzDirectory) dirs.Add((WzDirectory)node.Tag);
         else if (node.Tag is WzImage) imgs.Add((WzImage)node.Tag);
     }
     WzClassicXmlSerializer serializer = new WzClassicXmlSerializer(UserSettings.Indentation, UserSettings.LineBreakType, true);
     threadDone = false;
     runningThread = new Thread(new ParameterizedThreadStart(RunWzImgDirsExtraction));
     runningThread.Start((object)new object[] { dirs, imgs, outPath, serializer });
     new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
 }
Exemplo n.º 4
0
 private void xMLToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog() { Title = HaRepacker.Properties.Resources.SelectWz, Filter = string.Format("{0}|*.wz", HaRepacker.Properties.Resources.WzFilter), Multiselect = true };
     if (dialog.ShowDialog() != DialogResult.OK) return;
     FolderBrowserDialog folderDialog = new FolderBrowserDialog() { Description = HaRepacker.Properties.Resources.SelectOutDir };
     if (folderDialog.ShowDialog() != DialogResult.OK) return;
     WzClassicXmlSerializer serializer = new WzClassicXmlSerializer(UserSettings.Indentation, UserSettings.LineBreakType, false);
     threadDone = false;
     new Thread(new ParameterizedThreadStart(RunWzFilesExtraction)).Start((object)new object[] { dialog.FileNames, folderDialog.SelectedPath, encryptionBox.SelectedIndex, serializer });
     new Thread(new ParameterizedThreadStart(ProgressBarThread)).Start(serializer);
 }