/// <summary> /// Creates and writes a PBO from a folder to the given output /// </summary> /// <param name="input">Folder to create from</param> /// <param name="output">Folder to output ot</param> public static bool CreateAndWritePbo(DirectoryInfo input, DirectoryInfo output) { PboFile pbo = CreatePboFromFolder(input); pbo.WriteAsPboIn(output.FullName); return(File.Exists(Path.Combine(output.FullName, pbo.FileName))); }
/// <summary> /// Unpacks a PBO into a given folder /// </summary> /// <param name="pbo">Path to PBO</param> /// <param name="output">Path to unpack in</param> public static void UnPackPbo(FileInfo pbo, DirectoryInfo output) { if (!pbo.Exists) { return; } PboFile.FromPbo(pbo.FullName).ExtractTo(output.FullName); }
public static void Pack(ServerMod sm) { string folderPath = Path.Combine(Program.Settings.GitDirectory, sm.GitPath); string modPath = Path.Combine(Program.Settings.GitDirectory, sm.Name); if (sm.UseObfuSQF) { Console.WriteLine($"Running ObfuSQF for {sm.Name}\n"); string obfuPath = Path.Combine(Program.Settings.ObfuSQFDirectory, "ObfuSQF_CMD.exe"); string type = sm.ObfuSQFMission ? "Mission" : "Mod"; ProcessStartInfo obfu = new ProcessStartInfo(obfuPath); obfu.Arguments = $"--token {Program.Settings.ObfuSQFToken} --input \"{folderPath}\" --type {type} --output \"{modPath}.pbo\""; obfu.UseShellExecute = false; obfu.CreateNoWindow = true; ObfuProcs.Add(Process.Start(obfu)); } else { Console.WriteLine($"Packing {sm.Name}\n"); PboFile pbo = new PboFile(); foreach (string s in Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories)) { string path = s.Replace(folderPath, ""); if (path.StartsWith(@"\")) { path = path.Substring(1); } string file = File.ReadAllText(s); pbo.AddEntry(path, Encoding.UTF8.GetBytes(file)); } pbo.Save($"{modPath}.pbo"); } }
static void ParseReplayLog(string replayName, Stream file) { var key = new ReplayKey( replayName.Substring(0, 2), DateTime.ParseExact(replayName.Substring(3, 19), "yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture) ); if (ExistingRecords.Contains(key)) { return; } var stream = PboFile.FromStream(file).OpenFile("log.txt"); if (stream != null) { using (var input = new StreamReader(stream)) { var p = new ReplayProcessor(input); Replay replay; try { replay = p.ProcessReplay(); if (replay != null) { Interlocked.Increment(ref counterParsed); } } catch (ParseException e) { exceptions.Writer.TryWrite(Tuple.Create(replayName, (Exception)e)); replay = p.GetResult(); } Interlocked.Increment(ref counterProcessed); if (replay != null) { replay.Server = replayName.Substring(0, 2); queue.Writer.TryWrite(replay); } } } }
/// <summary> /// Creates a PBO from a folder /// </summary> /// <param name="input">Folder to create from</param> /// <returns></returns> public static PboFile CreatePboFromFolder(DirectoryInfo input) { var pbo = new PboFile(); foreach (FileInfo f in input.EnumerateFiles("*.*", SearchOption.AllDirectories)) { string path = f.FullName.Replace(input.FullName, "").TrimStart('\\'); if (!path.StartsWith(".git")) { var entry = new PboEntry(path, f.FullName); entry.Path = entry.Path.Replace('/', '\\'); // Fix for building PBOs on Linux if (entry.Path.StartsWith(@"\")) { // Further fix for linux entry.Path = entry.Path.TrimStart('\\'); } pbo.Add(entry); } } pbo.FileName = input.Name; pbo.MissionName = input.Name; return(pbo); }
public async Task <ActionResult> Get(string p, string r) { var uri = new Uri(p); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("replays"); var blob = container.GetBlockBlobReference(uri.Segments[uri.Segments.Length - 1] + "/log.txt"); if (r != null || !await blob.ExistsAsync()) { var file = new MemoryStream(); if (uri.Scheme == "ftp") { var userInfo = uri.UserInfo.Split(':'); using (var ftpClient = new FtpClient(new FtpClientConfiguration { Host = uri.Host, Port = uri.Port, Username = userInfo[0], Password = userInfo[1] })) { await ftpClient.LoginAsync(); using (var stream = await ftpClient.OpenFileReadStreamAsync(uri.LocalPath)) { await stream.CopyToAsync(file); } await ftpClient.LogOutAsync(); } } else if (uri.Scheme.StartsWith("http")) { using (var httpClient = new HttpClient()) { using (var stream = await httpClient.GetStreamAsync(uri)) { await stream.CopyToAsync(file); } } } var archive = SevenZipArchive.Open(file); using (var reader = archive.ExtractAllEntries()) { while (reader.MoveToNextEntry()) { foreach (var f in PboFile.EnumerateEntries(reader.OpenEntryStream())) { if (f.Path == "log.txt") { blob.Properties.CacheControl = "public, max-age=31536000"; blob.Properties.ContentType = "text/plain"; using (var s = new MemoryStream(f.FileContents.Length)) using (var input = new StreamReader(new MemoryStream(f.FileContents))) using (var output = new StreamWriter(s)) { ReplayToJson.Normalize(input, output); s.Seek(0, SeekOrigin.Begin); await blob.UploadFromStreamAsync(s); await blob.SetPropertiesAsync(); return(RedirectPermanent(blob.Uri.ToString())); //File(f.FileContents, "text/plain"); } } } } } return(NotFound()); } else { return(RedirectPermanent(blob.Uri.ToString())); } }
public static void Pack(ServerMod sm) { string gitName = Path.GetFileNameWithoutExtension(sm.GitUrl); string gitPath = Path.Combine(Program.Settings.GitDirectory, gitName); string folderPath = Path.Combine(gitPath, sm.Name); string modPath = Path.Combine(Program.Settings.GitDirectory, sm.Name); Console.WriteLine($"{folderPath} : {modPath}"); if (sm.PackingMethod == PackingMethod.ObfuSQF) { Console.WriteLine($"Running ObfuSQF for {sm.Name}\n"); string obfuPath = Path.Combine(Program.Settings.ObfuSQFDirectory, "ObfuSQF_CMD.exe"); string type = sm.ObfuSQFMission ? "Mission" : "Mod"; ProcessStartInfo obfu = new ProcessStartInfo(obfuPath) { Arguments = $"--token {Program.Settings.ObfuSQFToken} --input \"{folderPath}\" --type {type} --output \"{modPath}.pbo\"", UseShellExecute = false, CreateNoWindow = true }; ObfuProcs.Add(Process.Start(obfu)); } else if (sm.PackingMethod == PackingMethod.Normal) { Console.WriteLine($"Packing {sm.Name}\n"); PboFile pbo = new PboFile(); foreach (string s in Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories)) { string filename = Path.GetFileName(s); if (filename == "mission.sqm") { string Rapify = Path.Combine(Program.Settings.ToolsDirectory, "CfgConvert", "CfgConvert.exe"); if (File.Exists(Rapify) /*&& false*/) { Console.WriteLine("Binarising SQM"); Process.Start(new ProcessStartInfo { WorkingDirectory = folderPath, FileName = Rapify, Arguments = $"-bin {s}", UseShellExecute = false, CreateNoWindow = true }).WaitForExit(); } } string path = s.Replace(folderPath, ""); if (path.StartsWith(@"\")) { path = path.Substring(1); } //string file = File.ReadAllText(s); //pbo.AddEntry(path, Encoding.UTF8.GetBytes(file)); byte[] file = File.ReadAllBytes(s); pbo.AddEntry(path, file); } pbo.Save($"{modPath}.pbo"); } else if (sm.PackingMethod == PackingMethod.SqfSafe) { Console.WriteLine($"Running SqfSafe for {sm.Name}\n"); string obfuPath = Path.Combine(Program.Settings.SqfSafeDirectory, "SqfSafe-CLI.exe"); ProcessStartInfo obfu = new ProcessStartInfo(obfuPath) { Arguments = $"--token {Program.Settings.SqfSafeToken} -f \"{folderPath}\" -p \"{sm.SqfSafeProfile}\" -o \"{modPath}.pbo\"", UseShellExecute = false, CreateNoWindow = true }; ObfuProcs.Add(Process.Start(obfu)); } else { Console.WriteLine($"Packing Method not Supported."); Util.Assert(false); } }