Ejemplo n.º 1
0
        /// <summary>
        /// Pack a folder into .pbo format
        /// </summary>
        /// <param name="pbo"></param>
        /// <returns>bool</returns>
        internal static bool PackPBO(PBOFile pbo, out Exception exception)
        {
            try
            {
                exception = null;
                string folderPath = Path.Combine(DLL.ConfigValues.GitDirectory, pbo.GitBranch);
                string modPath    = Path.Combine(DLL.ConfigValues.GitDirectory, pbo.Name);

                Console.WriteLine($"Packing {pbo.Name}\n");

                PboFile pboFile = new PboFile();
                foreach (string files in Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories))
                {
                    string path = files.Replace(folderPath, "");
                    if (path.StartsWith(@"\"))
                    {
                        path = path.Substring(1);
                    }
                    string file = File.ReadAllText(files);
                    pboFile.AddEntry(path, Encoding.UTF8.GetBytes(file));
                }

                string modDirectory = modPath + ".pbo";

                pboFile.Save(modDirectory);
                return(File.Exists(modDirectory));
            }
            catch (IOException ex)
            {
                exception = ex;
                return(false);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Moves a PBO to new location
        /// </summary>
        /// <param name="pbo"></param>
        /// <returns></returns>
        internal static bool MovePBO(PBOFile pbo, out Exception exception)
        {
            string modPath    = Path.Combine(DLL.ConfigValues.GitDirectory, pbo.Name) + ".pbo";
            string serverPath = Path.Combine(pbo.ServerPath, pbo.Name) + ".pbo";

            if (pbo.ModType != PboModType.Mission)
            {
                serverPath = Path.Combine(pbo.ServerPath, "addons", pbo.Name) + ".pbo";
            }

            try
            {
                exception = null;
                File.Copy(modPath, serverPath, true);
                Console.WriteLine($"Moved ({pbo.Name}): {modPath} => {serverPath}");
                return(File.Exists(serverPath));
            }
            catch (IOException ex)
            {
                exception = ex;
                return(false);
            }
        }
Ejemplo n.º 3
0
 internal static bool MovePBO(PBOFile pbo) => MovePBO(pbo, out _);
Ejemplo n.º 4
0
 internal static bool PackPBO(PBOFile pbo) => PackPBO(pbo, out _);
Ejemplo n.º 5
0
 internal static bool RandomizePBO(PBOFile pbo) => RandomizePBO(pbo, out _);
Ejemplo n.º 6
0
        /// <summary>
        /// Randomizes PBO variables and functions
        /// </summary>
        /// <param name="pbo"></param>
        /// <returns>bool</returns>
        internal static bool RandomizePBO(PBOFile pbo, out Exception exception)
        {
            exception = null;
            List <string> badExtensions = new List <string>()
            {
                "ogg", "paa", "jpg", "png", "p3d", "wav", "tga", "dds", "rvmat", "ods", "fxy", "lip", "csv", "kb", "bik", "bikb", "html", "htm", "biedi"
            };

            try
            {
                string folderPath = Path.Combine(DLL.ConfigValues.GitDirectory, pbo.GitBranch);

                Console.WriteLine($"Begining {pbo.Name} obfuscation");

                foreach (string file in (Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories)))
                {
                    if (IsExtension(file, badExtensions))
                    {
                        continue;
                    }

                    string outName  = file;
                    string contents = File.ReadAllText(outName);

                    if (pbo.RandomizeGlobalVariables)
                    {
                        contents = RenameVariables(contents, DLL._globalVars);
                    }
                    if (pbo.RandomizeLocalVariables)
                    {
                        contents = RenameVariables(contents, DLL._localVars);
                    }
                    if (pbo.RandomizeFunctions)
                    {
                        contents = RenameVariables(file, out outName, contents, DLL._scriptFuncs);
                    }
                    if (pbo.SingleLineFunctions && IsExtension(file, "sqf"))
                    {
                        contents = OneLine(contents);
                    }

                    File.WriteAllText(file, contents);
                    if (file == outName)
                    {
                        continue;             //Move to next file
                    }
                    File.Move(file, outName); //Change file name
                }

                Console.WriteLine($"{pbo.Name} obfuscated.");
                return(true);
            }
            catch (IOException ex)
            {
                exception = ex;
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            return(false);
        }
Ejemplo n.º 7
0
 internal static bool DownloadPBO(PBOFile pbo) => DownloadPBO(pbo, out _);
Ejemplo n.º 8
0
        /// <summary>
        /// Downloads PBO from a gitserver
        /// </summary>
        /// <param name="pbo"></param>
        /// <returns>bool</returns>
        internal static bool DownloadPBO(PBOFile pbo, out Exception exception)
        {
            try
            {
                exception = null;
                string token   = pbo.GitToken.Replace("token ", "");
                string gitPath = Path.Combine(DLL.ConfigValues.GitDirectory + "/git.zip");

                if (!Directory.Exists(DLL.ConfigValues.GitDirectory))
                {
                    Directory.CreateDirectory(DLL.ConfigValues.GitDirectory);
                }

                using (var webClient = new WebClient())
                {
                    if (pbo.GitServer == GitServer.GitHub)
                    {
                        webClient.Headers.Add("Authorization", "token " + token);
                    }
                    else if (pbo.GitServer == GitServer.GitLab)
                    {
                        webClient.Headers.Add("Private-Token", token);
                    }
                    else
                    {
                        throw new Exception("Unknown GitServer");
                    }
                    webClient.DownloadFile(pbo.GitUrl, gitPath);
                };

                if (Directory.Exists(Path.Combine(DLL.ConfigValues.GitDirectory, pbo.GitBranch)))
                {
                    Directory.Delete(DLL.ConfigValues.GitDirectory, true);
                }
                Directory.CreateDirectory(DLL.ConfigValues.GitDirectory);

                if (pbo.GitServer == GitServer.GitLab)
                {
                    // very dirty hack for gitlab stupid file bullshit
                    using (ZipArchive archive = ZipFile.OpenRead(gitPath))
                    {
                        string folderName = archive.Entries[0].FullName;
                        foreach (ZipArchiveEntry entry in archive.Entries.Skip(1))
                        {
                            string name = DLL.ConfigValues.GitDirectory + "/" + entry.FullName.Replace(folderName, "");
                            if (entry.FullName.EndsWith("/"))
                            {
                                Directory.CreateDirectory(name);
                            }
                            else
                            {
                                entry.ExtractToFile(name);
                            }
                        }
                    }
                    return(true);
                }

                ZipFile.ExtractToDirectory(gitPath, DLL.ConfigValues.GitDirectory);

                return(true);
            }
            catch (Exception ex)
            {
                exception = ex;
                return(false);
            }
        }