protected void DownloadExtractAndDelete(string url, string path) { // generate a temp file name var tempfile = MakeTempFile("7z"); // download the archive PBW.Download(url, tempfile); // extract the archive PBW.Log.Write("Extracting {0} into {1}".F(tempfile, path)); var x = new SevenZipExtractor(tempfile); x.ExtractArchive(path); // log file list PBW.Log.Write("List of files extracted:"); foreach (var f in x.ArchiveFileNames.Select(f => Path.Combine(path, f))) { // lowercase it, requires 2 steps since Windows won't let you rename a file changing only the case // disabled this feature since it was causing issues with combat/movement files not being downloaded from PBW and it was only used as a workaround for a game with an uppercase name //var temp = MakeTempFile(Path.GetExtension(f)); //File.Move(f, temp); //var f2 = f.ToLowerInvariant(); var f2 = f; //File.Move(temp, f2); PBW.Log.Write("\t" + Path.GetFileName(f2)); } // delete the archive PBW.Log.Write("Deleting {0}".F(tempfile)); File.Delete(tempfile); }
public void ClearHold(string reason) { var url = "http://pbw.spaceempires.net/games/{0}/clear-hold".F(Code); PBW.Log.Write("Attempting to clear hold on auto processing for {0}.".F(Code)); var fields = new Dictionary <string, string>(); PBW.SubmitForm(url, fields, "clearing hold on " + Code); }
// TODO - replace turn // TODO - rollback turn // TODO - upload host PLR // TODO - upload GSU public void PlaceHold(string reason) { var url = "http://pbw.spaceempires.net/games/{0}/hold-turn".F(Code); PBW.Log.Write("Attempting to place hold on auto processing for {0}.".F(Code)); var fields = new Dictionary <string, string> { { "hold_message", reason }, }; PBW.SubmitForm(url, fields, "placing hold on " + Code); }
/// <summary> /// Uploads player turn (commands) for this game. /// </summary> public void UploadTurn() { // get list of files var path = GetSavePath(); var files = GetFiles(path, GenerateArgumentsOrFilter(Engine.PlayerTurnUploadFilter)); // send to PBW var url = "http://pbw.spaceempires.net/games/{0}/player-turn/upload".F(Code); if (files.Count() != 1) { throw new InvalidOperationException("Can only upload one PLR file at a time. " + files.Count() + " files were submitted."); } PBW.Log.Write($"Uploading player commands {path} for {this}."); PBW.Upload(files.Single(), url, "plr_file"); Status = PlayerStatus.Uploaded; }
protected void ArchiveUploadAndDeleteArchive(IEnumerable <string> files, string url, string uploadFormParam, HttpStatusCode expectedStatus = HttpStatusCode.OK) { // generate a temp file name var tempfile = MakeTempFile("7z"); PBW.Log.Write("Archiving files into {0}:".F(tempfile)); // archive the files var c = new SevenZipCompressor(); var files2 = files.ToArray(); foreach (var f in files2) { PBW.Log.Write("\t" + f); } c.CompressFiles(tempfile, files2); // upload the archive PBW.Upload(tempfile, url, uploadFormParam, expectedStatus); // delete the archive File.Delete(tempfile); }