コード例 #1
0
        private void ExtractSZSButton_Click(object sender, EventArgs e)
        {
            string result = "Successfully extracted MSBTs and XLIFFs from SZS file.";

            SanitizeFolderPath(extractingFolderTextBox, ref extractingDirectory);
            OpenFile(extractingSZSFilename);

            try
            {
                foreach (MsbtFile file in msbtFiles)
                {
                    if (!string.IsNullOrWhiteSpace(Path.GetDirectoryName(file.Name)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(file.Name));
                    }

                    MSBT msbt = new MSBT(file.Content);

                    if (!extractingDirectory.Exists)
                    {
                        Directory.CreateDirectory(extractingDirectory.FullName);
                    }

                    string msbtFilename = Path.GetFileNameWithoutExtension(file.Name);
                    msbt.SaveFile(Path.Combine(extractingDirectory.FullName, Path.GetFileName(file.Name)));
                    msbt.ExportXLIFF(Path.Combine(extractingDirectory.FullName, msbtFilename + ".xliff"));
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            MessageBox.Show(result, "Extracting MSBTs and XLIFFs", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #2
0
        private void PackXLIFFSButton_Click(object sender, EventArgs e)
        {
            string result = "Successfully packed XLIFFs into SZS file.";

            SanitizeFolderPath(packingFolderTextBox, ref packingDirectory);

            try
            {
                FileInfo[] msbtFiles  = packingDirectory.GetFiles("*.msbt");
                FileInfo[] xliffFiles = packingDirectory.GetFiles("*.xliff");

                Dictionary <string, FileInfo> matches    = new Dictionary <string, FileInfo>();
                Dictionary <string, FileInfo> nonMatches = new Dictionary <string, FileInfo>();

                foreach (FileInfo msbtFile in msbtFiles)
                {
                    string msbtName = Path.GetFileNameWithoutExtension(msbtFile.FullName);

                    foreach (FileInfo xliffFile in xliffFiles)
                    {
                        string xliffName = Path.GetFileNameWithoutExtension(xliffFile.FullName);

                        if (msbtName == xliffName)
                        {
                            matches.Add(msbtName, msbtFile);
                            break;
                        }
                        else
                        {
                            if (!matches.ContainsKey(xliffName) && !nonMatches.ContainsKey(msbtName))
                            {
                                nonMatches.Add(msbtName, msbtFile);
                            }
                        }
                    }
                }

                SARC sarc = new SARC
                {
                    padding   = globalPadding,
                    byteOrder = ByteOrder.LittleEndian
                };

                foreach (string file in matches.Keys)
                {
                    try
                    {
                        MSBT   msbt     = new MSBT(matches[file].FullName);
                        string filePath = Path.Combine(Path.GetDirectoryName(matches[file].FullName), Path.GetFileNameWithoutExtension(matches[file].FullName) + ".xliff");
                        msbt.ImportXLIFF(filePath);
                        sarc.files.Add(Path.GetFileName(matches[file].FullName), msbt.ExportFileBytes());
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                }

                foreach (string file in nonMatches.Keys)
                {
                    try
                    {
                        MSBT msbt = new MSBT(nonMatches[file].FullName);
                        sarc.files.Add(Path.GetFileName(nonMatches[file].FullName), msbt.ExportFileBytes());
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                }

                File.WriteAllBytes(packingSZSFilename, YAZ0.Compress(sarc.Rebuild()));
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            MessageBox.Show(result, "Packing XLIFFs", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }