private void OpenFile(string file)
 {
     msbtFiles.Clear();
     if (Path.GetExtension(file).Equals(".szs"))
     {
         byte[] szs = YAZ0.Decompress(File.ReadAllBytes(file));
         if (new FileInput(szs).ReadString(0, 4).Equals("SARC"))
         {
             SARC sarc = new SARC();
             sarc.Read(szs);
             globalPadding = sarc.padding;
             foreach (string name in sarc.files.Keys)
             {
                 msbtFiles.Add(new MsbtFile()
                 {
                     Name = name, Content = sarc.files[name]
                 });
             }
         }
     }
 }
        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);
        }