SaveToFile() public method

public SaveToFile ( string Filename ) : void
Filename string
return void
示例#1
0
        public static void GenerateMgsv(string MgsvFile, string ModName, string SourceFolder)
        {
            ModEntry metaData = new ModEntry();

            metaData.Name               = ModName;
            metaData.Author             = "SnakeBite";
            metaData.MGSVersion.Version = "0.0.0.0";
            metaData.SBVersion.Version  = ModManager.GetSBVersion().ToString();
            metaData.Version            = "[QM]";
            metaData.Description        = "[Generated by SnakeBite]";
            metaData.Website            = "";

            List <ModFpkEntry> fpkEntries = new List <ModFpkEntry>();
            List <ModQarEntry> qarEntries = new List <ModQarEntry>();

            foreach (var File in Directory.GetFiles(SourceFolder, "*", SearchOption.AllDirectories))
            {
                string ShortFileName = File.Substring(SourceFolder.Length + 1);
                if (File.ToLower().Contains(".fpk"))
                {
                    // do fpk
                    var fpkCont = GzsLib.ListArchiveContents <FpkFile>(File);
                    foreach (var fpkFile in fpkCont)
                    {
                        fpkEntries.Add(new ModFpkEntry()
                        {
                            FpkFile    = ShortFileName,
                            FilePath   = fpkFile,
                            SourceType = FileSource.Mod
                        });
                    }
                }
                else
                {
                    // do qar
                    qarEntries.Add(new ModQarEntry()
                    {
                        FilePath = ShortFileName, SourceType = FileSource.Mod
                    });
                }
            }

            metaData.ModQarEntries = qarEntries;
            metaData.ModFpkEntries = fpkEntries;
            metaData.SaveToFile(Path.Combine(SourceFolder, "metadata.xml"));

            FastZip makeZip = new FastZip();

            makeZip.CreateZip(MgsvFile, SourceFolder, true, ".*");
        }
示例#2
0
        private void DoBuild(string BuildFile)
        {
            ModEntry modMetaData = new ModEntry();

            modMetaData.Name               = textModName.Text;
            modMetaData.Author             = textModAuthor.Text;
            modMetaData.Version            = textModVersion.Text;
            modMetaData.MGSVersion.Version = comboForVersion.Text;
            modMetaData.Website            = textModWebsite.Text;
            modMetaData.Description        = textModDescription.Text;
            modMetaData.SaveToFile(textModPath.Text + "\\metadata.xml");

            Build.BuildArchive(textModPath.Text, modMetaData, BuildFile);
        }
示例#3
0
        public static void GenerateMgsv(string MgsvFile, string ModName, string SourceFolder)
        {
            ModEntry metaData = new ModEntry();
            metaData.Name = ModName;
            metaData.Author = "SnakeBite";
            metaData.MGSVersion.Version = "0.0.0.0";
            metaData.SBVersion.Version = "0.8.0.0";
            metaData.Version = "[QM]";
            metaData.Description = "[Generated by SnakeBite]";
            metaData.Website = "";

            List<ModFpkEntry> fpkEntries = new List<ModFpkEntry>();
            List<ModQarEntry> qarEntries = new List<ModQarEntry>();

            foreach(var File in Directory.GetFiles(SourceFolder, "*", SearchOption.AllDirectories))
            {
                string ShortFileName = File.Substring(SourceFolder.Length + 1);
                if(File.ToLower().Contains(".fpk"))
                {
                    // do fpk
                    var fpkCont = GzsLib.ListArchiveContents<FpkFile>(File);
                    foreach(var fpkFile in fpkCont)
                    {
                        fpkEntries.Add(new ModFpkEntry()
                        {
                            FpkFile = ShortFileName,
                            FilePath = fpkFile,
                            SourceType = FileSource.Mod
                        });
                    }
                } else
                {
                    // do qar
                    qarEntries.Add(new ModQarEntry() { FilePath = ShortFileName, SourceType = FileSource.Mod });
                }
            }

            metaData.ModQarEntries = qarEntries;
            metaData.ModFpkEntries = fpkEntries;
            metaData.SaveToFile(Path.Combine(SourceFolder, "metadata.xml"));

            FastZip makeZip = new FastZip();
            makeZip.CreateZip(MgsvFile, SourceFolder, true, ".*");
        }
示例#4
0
        private void buttonMetaSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog SaveMeta = new SaveFileDialog();

            SaveMeta.Filter = "Metadata XML|*.xml";
            DialogResult SaveResult = SaveMeta.ShowDialog();

            if (SaveResult != DialogResult.OK)
            {
                return;
            }

            ModEntry modMetaData = new ModEntry();

            modMetaData.Name               = textModName.Text;
            modMetaData.Author             = textModAuthor.Text;
            modMetaData.Version            = textModVersion.Text;
            modMetaData.MGSVersion.Version = comboForVersion.Text;
            modMetaData.Website            = textModWebsite.Text;
            modMetaData.Description        = textModDescription.Text;
            modMetaData.SaveToFile(SaveMeta.FileName);
        }
示例#5
0
        public static void BuildArchive(string SourceDir, ModEntry metaData, string outputFilePath)
        {
            Debug.LogLine($"[BuildArchive] {SourceDir}.");
            HashingExtended.ReadDictionary();
            string buildDir = Directory.GetCurrentDirectory() + "\\_build";

            try
            {
                if (Directory.Exists(buildDir))
                {
                    Directory.Delete(buildDir, true);
                }
            }
            catch
            {
                Debug.LogLine(string.Format("[BuildArchive] preexisting _build directory could not be deleted: {0}", buildDir));
            }

            Directory.CreateDirectory("_build");

            List <string> fpkFiles = Directory.GetFiles(SourceDir, "*.fpk*", SearchOption.AllDirectories).ToList();

            for (int i = fpkFiles.Count - 1; i >= 0; i--)
            {
                string fpkFile = fpkFiles[i].Substring(SourceDir.Length + 1);
                if (!fpkFile.StartsWith("Assets"))
                {
                    string updatedFileName = HashingExtended.UpdateName(fpkFile);
                    if (updatedFileName != null)
                    {
                        updatedFileName = SourceDir + updatedFileName.Replace('/', '\\');
                        if (fpkFiles.Contains(updatedFileName))
                        {
                            fpkFiles.Remove(fpkFiles[i]);
                        }
                    }
                }
            }

            List <string> fpkFolders = ListFpkFolders(SourceDir);

            for (int i = fpkFolders.Count - 1; i >= 0; i--)
            {
                string fpkFolder = fpkFolders[i].Substring(SourceDir.Length + 1);
                if (!fpkFolder.StartsWith("Assets"))
                {
                    string updatedFileName = HashingExtended.UpdateName(fpkFolder.Replace("_fpk", ".fpk"));
                    if (updatedFileName != null)
                    {
                        updatedFileName = SourceDir + updatedFileName.Replace('/', '\\');
                        if (fpkFolders.Contains(updatedFileName.Replace(".fpk", "_fpk")) || fpkFiles.Contains(updatedFileName))
                        {
                            MessageBox.Show(string.Format("{0} was not packed or added to the build, because {1} (the unhashed filename of {0}) already exists in the mod directory.", Path.GetFileName(fpkFolders[i]), Path.GetFileName(updatedFileName)));
                            fpkFolders.Remove(fpkFolders[i]);
                        }
                    }
                }
            }

            // check for FPKs that must be built and build
            metaData.ModFpkEntries = new List <ModFpkEntry>();
            List <string> builtFpks = new List <string>();

            foreach (string FpkFullDir in fpkFolders)
            {
                foreach (ModFpkEntry fpkEntry in BuildFpk(FpkFullDir, SourceDir))
                {
                    metaData.ModFpkEntries.Add(fpkEntry);
                    if (!builtFpks.Contains(fpkEntry.FpkFile))
                    {
                        builtFpks.Add(fpkEntry.FpkFile);
                    }
                }
            }

            // check for other FPKs and build fpkentry data
            foreach (string SourceFile in Directory.GetFiles(SourceDir, "*.fpk*", SearchOption.AllDirectories))
            {
                //tex chunk0\Assets\tpp\pack\collectible\common\col_common_tpp_fpk\Assets\tpp\pack\resident\resident00.fpkl is the only fpkl, don't know what a fpkl is, but gzcore crashes on it.
                if (SourceFile.EndsWith(".fpkl") || SourceFile.EndsWith(".xml"))
                {
                    continue;
                }
                string FileName = Tools.ToQarPath(SourceFile.Substring(SourceDir.Length));
                if (!builtFpks.Contains(FileName))
                {
                    // unpack FPK and build FPK list
                    string fpkDir     = Tools.ToWinPath(FileName.Replace(".fpk", "_fpk"));
                    string fpkFullDir = Path.Combine(SourceDir, fpkDir);
                    if (!Directory.Exists(fpkFullDir))
                    {
                        GzsLib.ExtractArchive <FpkFile>(SourceFile, fpkFullDir);
                    }

                    var fpkContents = GzsLib.ListArchiveContents <FpkFile>(SourceFile);
                    foreach (string file in fpkContents)
                    {
                        if (!GzsLib.IsExtensionValidForArchive(file, fpkDir))
                        {
                            Debug.LogLine($"[BuildArchive] {file} is not a valid file for a {Path.GetExtension(fpkDir)} archive.");
                            continue;
                        }

                        metaData.ModFpkEntries.Add(new ModFpkEntry()
                        {
                            FilePath    = file,
                            FpkFile     = FileName,
                            ContentHash = Tools.GetMd5Hash(Path.Combine(SourceDir, fpkDir, Tools.ToWinPath(file)))
                        });
                    }
                }
            }

            // build QAR entries
            List <string> qarFiles = ListQarFiles(SourceDir);

            for (int i = qarFiles.Count - 1; i >= 0; i--)
            {
                string qarFile = qarFiles[i].Substring(SourceDir.Length + 1);
                if (!qarFile.StartsWith("Assets"))
                {
                    string updatedQarName = HashingExtended.UpdateName(qarFile);
                    if (updatedQarName != null)
                    {
                        updatedQarName = SourceDir + updatedQarName.Replace('/', '\\');
                        if (qarFiles.Contains(updatedQarName))
                        {
                            MessageBox.Show(string.Format("{0} was not added to the build, because {1} (the unhashed filename of {0}) already exists in the mod directory.", Path.GetFileName(qarFiles[i]), Path.GetFileName(updatedQarName)));
                            qarFiles.Remove(qarFiles[i]);
                        }
                    }
                }
            }

            metaData.ModQarEntries = new List <ModQarEntry>();
            foreach (string qarFile in qarFiles)
            {
                string subDir      = qarFile.Substring(0, qarFile.LastIndexOf("\\")).Substring(SourceDir.Length).TrimStart('\\'); // the subdirectory for XML output
                string qarFilePath = Tools.ToQarPath(qarFile.Substring(SourceDir.Length));

                if (!Directory.Exists(Path.Combine("_build", subDir)))
                {
                    Directory.CreateDirectory(Path.Combine("_build", subDir));                                                    // create file structure
                }
                File.Copy(qarFile, Path.Combine("_build", Tools.ToWinPath(qarFilePath)), true);

                ulong hash = Tools.NameToHash(qarFilePath);
                metaData.ModQarEntries.Add(new ModQarEntry()
                {
                    FilePath    = qarFilePath,
                    Compressed  = qarFile.EndsWith(".fpk") || qarFile.EndsWith(".fpkd") ? true : false,
                    ContentHash = Tools.GetMd5Hash(qarFile), Hash = hash
                });
            }

            //tex build external entries
            metaData.ModFileEntries = new List <ModFileEntry>();
            var externalFiles = ListExternalFiles(SourceDir);

            foreach (string externalFile in externalFiles)
            {
                string subDir           = externalFile.Substring(0, externalFile.LastIndexOf("\\")).Substring(SourceDir.Length).TrimStart('\\'); // the subdirectory for XML output
                string externalFilePath = Tools.ToQarPath(externalFile.Substring(SourceDir.Length));

                if (!Directory.Exists(Path.Combine("_build", subDir)))
                {
                    Directory.CreateDirectory(Path.Combine("_build", subDir));                                                    // create file structure
                }
                File.Copy(externalFile, Path.Combine("_build", Tools.ToWinPath(externalFilePath)), true);
                string strip = "/" + ExternalDirName;
                if (externalFilePath.StartsWith(strip))
                {
                    externalFilePath = externalFilePath.Substring(strip.Length);
                }
                //ulong hash = Tools.NameToHash(qarFilePath);
                metaData.ModFileEntries.Add(new ModFileEntry()
                {
                    FilePath = externalFilePath, ContentHash = Tools.GetMd5Hash(externalFile)
                });
            }

            metaData.SBVersion.Version = Application.ProductVersion;

            metaData.SaveToFile("_build\\metadata.xml");

            // build archive
            FastZip zipper = new FastZip();

            zipper.CreateZip(outputFilePath, "_build", true, "(.*?)");

            try
            {
                Directory.Delete("_build", true);
            }
            catch (Exception e)
            {
                Debug.LogLine(string.Format("[BuildArchive] _build directory could not be deleted: {0}", e.ToString()));
            }
        }
示例#6
0
        public static void BuildArchive(string SourceDir, ModEntry metaData, string OutputFile)
        {
            string buildDir = Directory.GetCurrentDirectory() + "\\build";

            if (Directory.Exists(buildDir))
            {
                Directory.Delete(buildDir, true);
            }

            Directory.CreateDirectory("_build");

            // check for FPKs that must be built and build
            metaData.ModFpkEntries = new List <ModFpkEntry>();
            List <string> builtFpks = new List <string>();

            foreach (string FpkDir in ListFpkFolders(SourceDir))
            {
                foreach (ModFpkEntry fpkEntry in BuildFpk(FpkDir, SourceDir))
                {
                    metaData.ModFpkEntries.Add(fpkEntry);
                    if (!builtFpks.Contains(fpkEntry.FpkFile))
                    {
                        builtFpks.Add(fpkEntry.FpkFile);
                    }
                }
            }

            // check for other FPKs and build fpkentry data
            foreach (string SourceFile in Directory.GetFiles(SourceDir, "*.fpk*", SearchOption.AllDirectories))
            {
                string FileName = Tools.ToQarPath(SourceFile.Substring(SourceDir.Length));
                if (!builtFpks.Contains(FileName))
                {
                    // unpack FPK and build FPK list

                    foreach (string file in GzsLib.ListArchiveContents <FpkFile>(SourceFile))
                    {
                        string fpkDir     = Tools.ToWinPath(FileName.Replace(".fpk", "_fpk"));
                        string fpkFullDir = Path.Combine(SourceDir, fpkDir);
                        if (!Directory.Exists(fpkFullDir))
                        {
                            GzsLib.ExtractArchive <FpkFile>(SourceFile, fpkFullDir);
                        }
                        metaData.ModFpkEntries.Add(new ModFpkEntry()
                        {
                            FilePath = file, FpkFile = FileName, ContentHash = Tools.GetMd5Hash(Path.Combine(SourceDir, fpkDir, Tools.ToWinPath(file)))
                        });
                    }
                }
            }

            // build QAR entries
            metaData.ModQarEntries = new List <ModQarEntry>();
            foreach (string qarFile in ListQarFiles(SourceDir))
            {
                string subDir      = qarFile.Substring(0, qarFile.LastIndexOf("\\")).Substring(SourceDir.Length).TrimStart('\\'); // the subdirectory for XML output
                string qarFilePath = Tools.ToQarPath(qarFile.Substring(SourceDir.Length));
                if (!Directory.Exists(Path.Combine("_build", subDir)))
                {
                    Directory.CreateDirectory(Path.Combine("_build", subDir));                                                    // create file structure
                }
                File.Copy(qarFile, Path.Combine("_build", Tools.ToWinPath(qarFilePath)), true);

                ulong hash = Tools.NameToHash(qarFilePath);
                metaData.ModQarEntries.Add(new ModQarEntry()
                {
                    FilePath = qarFilePath, Compressed = qarFile.Substring(qarFile.LastIndexOf(".") + 1).Contains("fpk") ? true : false, ContentHash = Tools.GetMd5Hash(qarFile), Hash = hash
                });
            }

            metaData.SBVersion.Version = "0.8.0.0";

            metaData.SaveToFile("_build\\metadata.xml");

            // build archive
            FastZip zipper = new FastZip();

            zipper.CreateZip(OutputFile, "_build", true, "(.*?)");

            Directory.Delete("_build", true);
        }
示例#7
0
        public static void BuildArchive(string SourceDir, ModEntry metaData, string outputFilePath)
        {
            string buildDir = Directory.GetCurrentDirectory() + "\\build";

            if (Directory.Exists(buildDir))
            {
                Directory.Delete(buildDir, true);
            }

            Directory.CreateDirectory("_build");

            // check for FPKs that must be built and build
            metaData.ModFpkEntries = new List <ModFpkEntry>();
            List <string> builtFpks = new List <string>();

            foreach (string FpkDir in ListFpkFolders(SourceDir))
            {
                foreach (ModFpkEntry fpkEntry in BuildFpk(FpkDir, SourceDir))
                {
                    metaData.ModFpkEntries.Add(fpkEntry);
                    if (!builtFpks.Contains(fpkEntry.FpkFile))
                    {
                        builtFpks.Add(fpkEntry.FpkFile);
                    }
                }
            }

            // check for other FPKs and build fpkentry data
            foreach (string SourceFile in Directory.GetFiles(SourceDir, "*.fpk*", SearchOption.AllDirectories))
            {
                //tex chunk0\Assets\tpp\pack\collectible\common\col_common_tpp_fpk\Assets\tpp\pack\resident\resident00.fpkl is the only fpkl, don't know what a fpkl is, but gzcore crashes on it.
                if (SourceFile.Contains(".fpkl"))
                {
                    continue;
                }

                string FileName = Tools.ToQarPath(SourceFile.Substring(SourceDir.Length));
                if (!builtFpks.Contains(FileName))
                {
                    // unpack FPK and build FPK list

                    foreach (string file in GzsLib.ListArchiveContents <FpkFile>(SourceFile))
                    {
                        string fpkDir     = Tools.ToWinPath(FileName.Replace(".fpk", "_fpk"));
                        string fpkFullDir = Path.Combine(SourceDir, fpkDir);
                        if (!Directory.Exists(fpkFullDir))
                        {
                            GzsLib.ExtractArchive <FpkFile>(SourceFile, fpkFullDir);
                        }
                        metaData.ModFpkEntries.Add(new ModFpkEntry()
                        {
                            FilePath = file, FpkFile = FileName, ContentHash = Tools.GetMd5Hash(Path.Combine(SourceDir, fpkDir, Tools.ToWinPath(file)))
                        });
                    }
                }
            }

            // build QAR entries
            metaData.ModQarEntries = new List <ModQarEntry>();
            foreach (string qarFile in ListQarFiles(SourceDir))
            {
                string subDir      = qarFile.Substring(0, qarFile.LastIndexOf("\\")).Substring(SourceDir.Length).TrimStart('\\'); // the subdirectory for XML output
                string qarFilePath = Tools.ToQarPath(qarFile.Substring(SourceDir.Length));
                if (!Directory.Exists(Path.Combine("_build", subDir)))
                {
                    Directory.CreateDirectory(Path.Combine("_build", subDir));                                                    // create file structure
                }
                File.Copy(qarFile, Path.Combine("_build", Tools.ToWinPath(qarFilePath)), true);

                ulong hash = Tools.NameToHash(qarFilePath);
                metaData.ModQarEntries.Add(new ModQarEntry()
                {
                    FilePath = qarFilePath, Compressed = qarFile.Substring(qarFile.LastIndexOf(".") + 1).Contains("fpk") ? true : false, ContentHash = Tools.GetMd5Hash(qarFile), Hash = hash
                });
            }

            //tex build external entries
            metaData.ModFileEntries = new List <ModFileEntry>();
            foreach (string externalFile in ListExternalFiles(SourceDir))
            {
                string subDir           = externalFile.Substring(0, externalFile.LastIndexOf("\\")).Substring(SourceDir.Length).TrimStart('\\'); // the subdirectory for XML output
                string externalFilePath = Tools.ToQarPath(externalFile.Substring(SourceDir.Length));

                if (!Directory.Exists(Path.Combine("_build", subDir)))
                {
                    Directory.CreateDirectory(Path.Combine("_build", subDir));                                                    // create file structure
                }
                File.Copy(externalFile, Path.Combine("_build", Tools.ToWinPath(externalFilePath)), true);
                string strip = "/" + ExternalDirName;
                if (externalFilePath.StartsWith(strip))
                {
                    externalFilePath = externalFilePath.Substring(strip.Length);
                }
                //ulong hash = Tools.NameToHash(qarFilePath);
                metaData.ModFileEntries.Add(new ModFileEntry()
                {
                    FilePath = externalFilePath, ContentHash = Tools.GetMd5Hash(externalFile)
                });
            }

            metaData.SBVersion.Version = SnakeBiteVersionStr;

            metaData.SaveToFile("_build\\metadata.xml");

            // build archive
            FastZip zipper = new FastZip();

            zipper.CreateZip(outputFilePath, "_build", true, "(.*?)");

            Directory.Delete("_build", true);
        }