public static void End(int id) { if (CurrentFile == null || CurrentFile.Id != id) { Util.SafeNotify($"END Channel mismatch! We have {CurrentFile?.Id} and supplied was {id}"); return; } if (CurrentFile.Type == FileType.Map) { var obj = Main.DeserializeBinary <ServerMap>(CurrentFile.Data.ToArray()) as ServerMap; if (obj == null) { Util.SafeNotify("ERROR DOWNLOADING MAP: NULL"); } else { Main.AddMap(obj); } } else if (CurrentFile.Type == FileType.Script) { var obj = Main.DeserializeBinary <ScriptCollection>(CurrentFile.Data.ToArray()) as ScriptCollection; if (obj == null) { Util.SafeNotify("ERROR DOWNLOADING SCRIPTS: NULL"); } else { Main.StartClientsideScripts(obj); if (Main.JustJoinedServer) { World.RenderingCamera = null; Main.MainMenu.TemporarilyHidden = false; Main.MainMenu.Visible = false; Main.JustJoinedServer = false; } Main.InvokeFinishedDownload(); } } CurrentFile.Dispose(); CurrentFile = null; }
public static bool StartDownload(int id, string path, FileType type, int len, string md5hash) { if (CurrentFile != null) { return(false); } if (type == FileType.Normal && Directory.Exists(FileTransferId._DOWNLOADFOLDER_ + path.Replace(Path.GetFileName(path), "")) && File.Exists(FileTransferId._DOWNLOADFOLDER_ + path)) { using (var md5 = MD5.Create()) using (var stream = File.OpenRead(FileTransferId._DOWNLOADFOLDER_ + path)) { var myData = md5.ComputeHash(stream); if (myData.Select(byt => byt.ToString("x2")).Aggregate((left, right) => left + right) == md5hash) { return(false); } } } CurrentFile = new FileTransferId(id, path, type, len); return(true); }
public static void Cancel() { CurrentFile = null; }