Exemple #1
0
        private void InitThread(string fileName, string dumpFolder, WzMapleVersion selectedValue)
        {
            WzListFile listFile = null;
            WzFile     regFile  = null;
            var        message  = String.Empty;

            try {
                if (fileName.EndsWith("List.wz", StringComparison.CurrentCultureIgnoreCase))
                {
                    listFile = new WzListFile(fileName, selectedValue);
                    listFile.ParseWzFile();
                }
                else
                {
                    List <WzFile> s = new List <WzFile>();
                    getWzExtensionFiles(fileName, s);
                    regFile = new WzFile(fileName, selectedValue, s);
                    regFile.ParseWzFile();
                }
            } catch (IOException ex) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "An IO error occurred: " + ex.Message;
            } catch (UnauthorizedAccessException) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "Please re-run this program as an administrator.";
            } catch (Exception ex) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "An error occurred while parsing this file: " + ex.Message;
            }
            if (!String.IsNullOrEmpty(message))
            {
                UpdateTextBoxInfo(Info, "Error while parsing file " + Path.GetFileName(fileName) + "\r\nMessage: " + message + "\r\nContinuing...", true);
                if (!fileName.EndsWith("List.wz"))
                {
                    IsError = true;
                }
                return;
            }
            if (regFile == null && listFile == null)
            {
                return;
            }
            var wzName  = Path.GetFileName(fileName);
            var nFolder = Path.Combine(dumpFolder, wzName);

            if (listFile == null && includeVersionInFolderBox.Checked)
            {
                nFolder += "_v" + regFile.Version;
            }
            nFolder = GetValidFolderName(nFolder, false);
            if (!Directory.Exists(nFolder))
            {
                Directory.CreateDirectory(nFolder);
            }
            if (listFile == null)
            {
                UpdateTextBoxInfo(versionBox, regFile.Version.ToString(CultureInfo.CurrentCulture), false);
            }
            if (listFile != null)
            {
                UpdateTextBoxInfo(Info, "Dumping data from " + wzName + " to " + nFolder + "...", true);
            }
            else if (includePngMp3Box.Checked)
            {
                UpdateTextBoxInfo(Info, "Dumping MP3s, PNGs and XMLs from " + wzName + " to " + nFolder + "...", true);
            }
            else
            {
                UpdateTextBoxInfo(Info, "Dumping XMLs from " + wzName + " to " + nFolder + "...", true);
            }
            if (listFile != null)
            {
                DumpListWz(listFile, wzName, nFolder, DateTime.Now);
                listFile.Dispose();
            }
            else
            {
                DirectoryDumperThread(regFile, new WzXml(this, dumpFolder, new DirectoryInfo(nFolder).Name, includePngMp3Box.Checked, SelectedLinkType));
            }
        }
Exemple #2
0
        private void InitThread(string fileName, string dumpFolder, WzMapleVersion selectedValue)
        {
            WzListFile listFile = null;
            WzFile     regFile  = null;
            var        message  = String.Empty;

            try {
                if (fileName.EndsWith("List.wz", StringComparison.CurrentCultureIgnoreCase))
                {
                    listFile = new WzListFile(fileName, selectedValue);
                    listFile.ParseWzFile();
                }
                else
                {
                    List <WzFile> s = new List <WzFile>();
                    getWzExtensionFiles(fileName, s);
                    regFile = new WzFile(fileName, selectedValue, s);
                    regFile.ParseWzFile();
                }
            } catch (IOException ex) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "發生IO錯誤: " + ex.Message;
            } catch (UnauthorizedAccessException) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "請以管理員權限重啟此程式";
            } catch (Exception ex) {
                if (regFile != null)
                {
                    regFile.Dispose();
                }
                message = "處理檔案中發生問題: " + ex.Message;
            }
            if (!String.IsNullOrEmpty(message))
            {
                UpdateTextBoxInfo(Info, "處理文件時發生錯誤 " + Path.GetFileName(fileName) + "\r\n訊息: " + message + "\r\nContinuing...", true);
                IsError = true;
                return;
            }
            if (regFile == null && listFile == null)
            {
                return;
            }
            var wzName  = Path.GetFileName(fileName);
            var nFolder = Path.Combine(dumpFolder, wzName);

            if (listFile == null && includeVersionInFolderBox.Checked)
            {
                nFolder += "_v" + regFile.Version;
            }
            nFolder = GetValidFolderName(nFolder, false);
            if (!Directory.Exists(nFolder))
            {
                Directory.CreateDirectory(nFolder);
            }
            if (listFile == null)
            {
                UpdateTextBoxInfo(versionBox, regFile.Version.ToString(CultureInfo.CurrentCulture), false);
            }
            if (listFile != null)
            {
                UpdateTextBoxInfo(Info, "提取資料從 " + wzName + " 到 " + nFolder + "...", true);
            }
            else if (includePngMp3Box.Checked)
            {
                UpdateTextBoxInfo(Info, "提取 MP3, PNG 和 XML 從 " + wzName + " 到 " + nFolder + "...", true);
            }
            else
            {
                UpdateTextBoxInfo(Info, "提取 XML 從 " + wzName + " 到 " + nFolder + "...", true);
            }
            if (listFile != null)
            {
                DumpListWz(listFile, wzName, nFolder, DateTime.Now);
                listFile.Dispose();
            }
            else
            {
                DirectoryDumperThread(regFile, new WzXml(this, dumpFolder, new DirectoryInfo(nFolder).Name, includePngMp3Box.Checked, SelectedLinkType));
            }
        }
Exemple #3
0
        private void DumpFile(object sender, EventArgs e)
        {
            CheckOutputPath();
            UpdateToolstripStatus("Parsing...");
            DisableButtons();
            var            filePath = WZFileTB.Text;
            FileAttributes attr     = File.GetAttributes(filePath);

            if (!attr.HasFlag(FileAttributes.Directory))
            {
                var ext = Path.GetExtension(filePath);
                if (ext != null && String.Compare(ext, ".img", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    DumpXmlFromWzImage(filePath);
                    return;
                }
                WzListFile listFile = null;
                WzFile     regFile  = null;
                try {
                    if (filePath.EndsWith("List.wz", StringComparison.CurrentCultureIgnoreCase))
                    {
                        listFile = new WzListFile(filePath, SelectedVersion);
                        listFile.ParseWzFile();
                    }
                    else
                    {
                        List <WzFile> s = new List <WzFile>();
                        getWzExtensionFiles(filePath, s);
                        regFile = new WzFile(filePath, SelectedVersion, s);
                        regFile.ParseWzFile();
                    }
                } catch (UnauthorizedAccessException) {
                    if (regFile != null)
                    {
                        regFile.Dispose();
                    }
                    MessageBox.Show("Please re-run this program as an administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    UpdateToolstripStatus("");
                    EnableButtons();
                    return;
                } catch (Exception ex) {
                    if (regFile != null)
                    {
                        regFile.Dispose();
                    }
                    MessageBox.Show("An error occurred while parsing this file: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    UpdateToolstripStatus("");
                    EnableButtons();
                    return;
                }
                if (listFile == null)
                {
                    versionBox.Text = regFile.Version.ToString(CultureInfo.CurrentCulture);
                }
                var fileName      = Path.GetFileName(filePath);
                var extractDir    = outputFolderTB.Text;
                var extractFolder = Path.Combine(extractDir, fileName);
                if (listFile == null && includeVersionInFolderBox.Checked)
                {
                    extractFolder += "_v" + regFile.Version;
                }
                if (File.Exists(extractFolder))
                {
                    extractFolder = GetValidFolderName(extractFolder, true);
                }
                if (Directory.Exists(extractFolder))
                {
                    var result = MessageBox.Show(extractFolder + " already exists.\r\nDo you want to overwrite that folder?\r\nNote: Clicking No will make a new folder.", "Folder Already Exists", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.Cancel)
                    {
                        if (regFile != null)
                        {
                            regFile.Dispose();
                        }
                        UpdateToolstripStatus("");
                        EnableButtons();
                        return;
                    }
                    if (result != DialogResult.Yes)
                    {
                        extractFolder = GetValidFolderName(extractFolder, false);
                    }
                }
                if (!Directory.Exists(extractFolder))
                {
                    Directory.CreateDirectory(extractFolder);
                }
                if (listFile != null)
                {
                    Info.AppendText("Dumping data from " + fileName + " to " + extractFolder + "...\r\n");
                }
                else if (includePngMp3Box.Checked)
                {
                    Info.AppendText("Dumping MP3s, PNGs and XMLs from " + fileName + " to " + extractFolder + "...\r\n");
                }
                else
                {
                    Info.AppendText("Dumping XMLs from " + fileName + " to " + extractFolder + "...\r\n");
                }
                if (listFile != null)
                {
                    DumpListWz(listFile, fileName, extractFolder, DateTime.Now);
                    listFile.Dispose();
                    EnableButtons();
                }
                else
                {
                    UpdateToolstripStatus("Preparing...");
                    CancelSource = new CancellationTokenSource();
                    CreateSingleDumperThread(regFile, new WzXml(this, extractDir, new DirectoryInfo(extractFolder).Name, includePngMp3Box.Checked, SelectedLinkType), fileName);
                }
            }
            else
            {
                var allFiles = Directory.GetFiles(filePath, "*.wz");
                if (allFiles.Length != 0)
                {
                    string filesFound = "WZ Files Found: ";
                    foreach (var fileName in allFiles)
                    {
                        filesFound += Path.GetFileName(fileName) + ", ";
                    }
                    Info.AppendText(filesFound.Substring(0, filesFound.Length - 2) + "\r\n");
                    allFiles = allFiles.Where(fileName => !Regex.IsMatch(fileName, "[0-9]{3}.wz$", RegexOptions.IgnoreCase)).ToArray();;
                    Array.Sort(allFiles, Compare);
                    CreateMultipleDumperThreads(filePath, allFiles, outputFolderTB.Text);
                }
                else
                {
                    MessageBox.Show("There are no WZ Files located in the selected folder. Please choose a different folder.", "No WZ Files Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    UpdateToolstripStatus("");
                    EnableButtons();
                }
            }
        }
Exemple #4
0
        private void DumpFile(object sender, EventArgs e)
        {
            UpdateToolstripStatus("處理中...");
            DisableButtons();
            var            filePath = WZFileTB.Text;
            FileAttributes attr     = File.GetAttributes(filePath);

            if (!attr.HasFlag(FileAttributes.Directory))
            {
                var ext = Path.GetExtension(filePath);
                if (ext != null && String.Compare(ext, ".img", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    DumpXmlFromWzImage(filePath);
                    return;
                }
                WzListFile listFile = null;
                WzFile     regFile  = null;
                try {
                    if (filePath.EndsWith("List.wz", StringComparison.CurrentCultureIgnoreCase))
                    {
                        listFile = new WzListFile(filePath, SelectedVersion);
                        listFile.ParseWzFile();
                    }
                    else
                    {
                        List <WzFile> s = new List <WzFile>();
                        getWzExtensionFiles(filePath, s);
                        regFile = new WzFile(filePath, SelectedVersion, s);
                        regFile.ParseWzFile();
                    }
                } catch (UnauthorizedAccessException) {
                    if (regFile != null)
                    {
                        regFile.Dispose();
                    }
                    MessageBox.Show("請使用管理員權限重新開啟此程式.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    UpdateToolstripStatus("");
                    EnableButtons();
                    return;
                } catch (Exception ex) {
                    if (regFile != null)
                    {
                        regFile.Dispose();
                    }
                    MessageBox.Show("發生錯誤,訊息: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    UpdateToolstripStatus("");
                    EnableButtons();
                    return;
                }
                if (listFile == null)
                {
                    versionBox.Text = regFile.Version.ToString(CultureInfo.CurrentCulture);
                }
                var fileName      = Path.GetFileName(filePath);
                var extractDir    = outputFolderTB.Text;
                var extractFolder = Path.Combine(extractDir, fileName);
                if (listFile == null && includeVersionInFolderBox.Checked)
                {
                    extractFolder += "_v" + regFile.Version;
                }
                if (File.Exists(extractFolder))
                {
                    extractFolder = GetValidFolderName(extractFolder, true);
                }
                if (Directory.Exists(extractFolder))
                {
                    var result = MessageBox.Show(extractFolder + " 已經存在.\r\n是否要覆蓋資料夾?\r\n提示: 點選 No 將會創建新資料夾.", "Folder Already Exists", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.Cancel)
                    {
                        if (regFile != null)
                        {
                            regFile.Dispose();
                        }
                        UpdateToolstripStatus("");
                        EnableButtons();
                        return;
                    }
                    if (result != DialogResult.Yes)
                    {
                        extractFolder = GetValidFolderName(extractFolder, false);
                    }
                }
                if (!Directory.Exists(extractFolder))
                {
                    Directory.CreateDirectory(extractFolder);
                }
                if (listFile != null)
                {
                    Info.AppendText("提取資料從 " + fileName + " 到 " + extractFolder + "...\r\n");
                }
                else if (includePngMp3Box.Checked)
                {
                    Info.AppendText("提取 MP3s, PNGs 和XMLs 從檔案 " + fileName + " 到 " + extractFolder + "...\r\n");
                }
                else
                {
                    Info.AppendText("提取 XML 從 " + fileName + " 到 " + extractFolder + "...\r\n");
                }
                if (listFile != null)
                {
                    DumpListWz(listFile, fileName, extractFolder, DateTime.Now);
                    listFile.Dispose();
                    EnableButtons();
                }
                else
                {
                    UpdateToolstripStatus("準備中...");
                    CancelSource = new CancellationTokenSource();
                    CreateSingleDumperThread(regFile, new WzXml(this, extractDir, new DirectoryInfo(extractFolder).Name, includePngMp3Box.Checked, SelectedLinkType), fileName);
                }
            }
            else
            {
                var allFiles = Directory.GetFiles(filePath, "*.wz");
                if (allFiles.Length != 0)
                {
                    string filesFound = "未找到WZ文件: ";
                    foreach (var fileName in allFiles)
                    {
                        filesFound += Path.GetFileName(fileName) + ", ";
                    }
                    Info.AppendText(filesFound.Substring(0, filesFound.Length - 2) + "\r\n");
                    // allFiles = allFiles.Where(fileName => !Regex.IsMatch(fileName, "[0-9]{3}.wz$", RegexOptions.IgnoreCase)).ToArray(); ;
                    Array.Sort(allFiles, Compare);
                    CreateMultipleDumperThreads(filePath, allFiles, outputFolderTB.Text);
                }
                else
                {
                    MessageBox.Show("所選擇的資料夾不包含Wz檔案. 請選擇其他資料夾.", "No WZ Files Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    UpdateToolstripStatus("");
                    EnableButtons();
                }
            }
        }