private void OnDownloadFileComplete(object sender, DownloadPackage e) { if (!DownloaderOptions.AutoQueueHandling) { MyDownloder.QueueNext(); } }
public static DownloadPackage LoadPackage(this DownloadPackage package, string episodePath) { var formattedPath = GetFilePath(episodePath); if (formattedPath == null) { return(null); } IFormatter formatter = new BinaryFormatter(); try { lock (FileLock) { Stream serializedStream = new FileStream(formattedPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite); var newPack = formatter.Deserialize(serializedStream) as DownloadPackage; serializedStream.Flush(); serializedStream.Close(); serializedStream.Dispose(); return(newPack); } } catch (FileNotFoundException) { return(null); } catch (SerializationException) { return(null); } }
public void ScheduleExtract(DownloadPackage pkg) { if (!File.Exists(Extractpath)) { Download dl = pkg.ScheduleDownload(this.Name,this.Url); ApplyDlStuff(dl); } }
public HttpResponseMessage Get(string id, string version) { Log.Submit(LogLevel.Debug, "GET request received"); HttpResponseMessage response = DownloadPackage.Download(Request, id, version); Log.Submit(LogLevel.Debug, "GET response ready"); return(response); }
public void ScheduleExtract(DownloadPackage pkg) { if (!File.Exists(Extractpath)) { Download dl = pkg.ScheduleDownload(this.Name, this.Url); ApplyDlStuff(dl); } }
internal void CallDownloadResume(DownloadPackage package) { if (OnDownloadResume == null) { return; } OnDownloadResume(this, package); }
internal void CallDownloadFileFail(DownloadPackage package) { if (OnDownloadFileFail == null) { return; } OnDownloadFileFail(this, package); }
internal void CallDownloadFileComplete(DownloadPackage package) { if (OnDownloadFileComplete == null) { return; } OnDownloadFileComplete(this, package); }
internal void CallDownloadFileStarted(DownloadPackage package) { if (OnDownloadFileStarted == null) { return; } OnDownloadFileStarted(this, package); }
public static void Delete(this DownloadPackage package, string episodePath) { var formattedPath = GetFilePath(episodePath); if (!File.Exists(formattedPath)) { return; } File.Delete(formattedPath); }
public Manager(IDownloadHelper downloadHelper) { this._downloadHelper = downloadHelper; _validator = new Validator(); _efManager = new EFManager(); _mailManager = new MailManager(); _linkManager = new LinkManager(); _downloadPackage = new DownloadPackage(); }
public void StopResumeDownloadOverFirstPackagePositionTest() { // arrange var packageCheckPoint = new DownloadPackage() { Address = DummyFileHelper.GetFileUrl(DummyFileHelper.FileSize16Kb) }; var stopThreshold = 4100; var totalReceivedBytes = 0L; var downloader = new DownloadService(Config); var isSavingStateOnCancel = false; var isSavingStateBeforCancel = false; downloader.DownloadProgressChanged += (s, e) => { totalReceivedBytes += e.ReceivedBytes.Length; isSavingStateBeforCancel |= downloader.Package.IsSaving; if (e.ReceivedBytesSize > stopThreshold) { // Stopping after start of downloading downloader.CancelAsync(); stopThreshold *= 2; // check point of package for once time packageCheckPoint.Chunks ??= downloader.Package.Chunks.Clone() as Chunk[]; } }; // act downloader.DownloadFileTaskAsync(packageCheckPoint.Address).Wait(); while (downloader.IsCancelled) { isSavingStateOnCancel |= downloader.Package.IsSaving; var firstCheckPointClone = new DownloadPackage() { Address = packageCheckPoint.Address, Chunks = packageCheckPoint.Chunks.Clone() as Chunk[] }; // resume download from first stopped point. downloader.DownloadFileTaskAsync(firstCheckPointClone).Wait(); } // assert Assert.IsTrue(downloader.Package.IsSaveComplete); Assert.IsFalse(downloader.Package.IsSaving); Assert.IsFalse(isSavingStateOnCancel); Assert.IsTrue(isSavingStateBeforCancel); Assert.AreEqual(DummyFileHelper.FileSize16Kb, downloader.Package.TotalFileSize); Assert.AreEqual(DummyFileHelper.FileSize16Kb, totalReceivedBytes); }
public virtual void Initial() { var testData = DummyData.GenerateOrderedBytes(DummyFileHelper.FileSize16Kb); _package = new DownloadPackage() { FileName = DummyFileHelper.SampleFile16KbName, Address = DummyFileHelper.GetFileWithNameUrl(DummyFileHelper.SampleFile16KbName, DummyFileHelper.FileSize16Kb), Chunks = new ChunkHub(Configuration).ChunkFile(DummyFileHelper.FileSize16Kb, 8), TotalFileSize = DummyFileHelper.FileSize16Kb }; foreach (var chunk in _package.Chunks) { chunk.Storage.WriteAsync(testData, (int)chunk.Start, (int)chunk.Length); } }
internal static void ScheduleAssetDownloads() { bool need = false; DownloadPackage dlp = new DownloadPackage("Assets", true); List<MinecraftAsset> needDl = new List<MinecraftAsset>(); assets.ForEach(a => { if (a.NeedsDownload()) { needDl.Add(a); Download dl = dlp.ScheduleDownload(a.Key, a.Url); dl.Downloaded += AssetDownloaded; need = true; } }); if(need) DownloadManager.ScheduleDownload(dlp); }
private void PackagesAreEqual(DownloadPackage source, DownloadPackage destination) { Assert.IsNotNull(source); Assert.IsNotNull(destination); Assert.IsNotNull(source.Chunks); Assert.IsNotNull(destination.Chunks); Assert.AreEqual(source.FileName, destination.FileName); Assert.AreEqual(source.ReceivedBytesSize, destination.ReceivedBytesSize); Assert.AreEqual(source.Address, destination.Address); Assert.AreEqual(source.TotalFileSize, destination.TotalFileSize); Assert.AreEqual(source.Chunks?.Length, destination.Chunks?.Length); for (int i = 0; i < source.Chunks.Length; i++) { AssertHelper.AreEquals(source.Chunks[i], destination.Chunks[i]); } }
static async Task <int> Main(string[] args) { ServicePointManager.DefaultConnectionLimit = 64; ThreadPool.SetMinThreads(workerThreads: 64, completionPortThreads: 4); var rootCommand = new RootCommand(); rootCommand.Add(DownloadAllVersions.GetCommand()); rootCommand.Add(DownloadPackage.GetCommand()); rootCommand.Add(Push.GetCommand()); rootCommand.Add(ParseRestoreLogs.GetCommand()); rootCommand.Add(ReplayRequestGraph.GetCommand()); rootCommand.Add(ConvertGraph.GetCommand()); rootCommand.Add(MergeTestResults.GetCommand()); rootCommand.Add(DumpRequestDurations.GetCommand()); return(await rootCommand.InvokeAsync(args)); }
public virtual void Initial() { var testData = DummyData.GenerateOrderedBytes(DownloadTestHelper.FileSize16Kb); Package = new DownloadPackage() { FileName = DownloadTestHelper.File16KbName, Address = DownloadTestHelper.File16KbUrl, Chunks = new ChunkHub(Configuration).ChunkFile(DownloadTestHelper.FileSize16Kb, 8), TotalFileSize = DownloadTestHelper.FileSize16Kb }; foreach (var chunk in Package.Chunks) { chunk.Storage.WriteAsync(testData, (int)chunk.Start, (int)chunk.Length); Package.AddReceivedBytes(chunk.Length); } }
private void UpdateDownloadInfo(DownloadPackage package) { var info = ""; for (var i = 0; i < package.Chunks.Length; i++) { Chunk chunk = package.Chunks[i]; if (chunk.Storage is FileStorage fileStorage) { info += $"Chunk[{i}]: {fileStorage.FileName} {fileStorage.GetLength()}bytes \n\r"; } else if (chunk.Storage is MemoryStorage memoryStorage) { info += $"Chunk[{i}]: {memoryStorage.GetLength()}bytes \n\r"; } } Model.InfoText = info; }
private void Downloader_DoWork(object sender, DoWorkEventArgs e) { DownloadEngine.Downloader downloader = new Downloader(); BeatmapsetPackage beatmapsetPackage = new BeatmapsetPackage(new Beatmapset(((string)e.Argument))); downloader.BeatmapsetPackage = beatmapsetPackage; DownloadPackage downloadPackage = new DownloadPackage(beatmapsetPackage.Beatmapset); packageCollection.Add(downloadPackage); beatmapsetPackage.ProgressChanged += delegate(object o, ProgressChangedEventArgs args) { downloadPackage.ProgressPercentage = args.ProgressPercentage; }; beatmapsetPackage.WriteFileCompleted += delegate(object o, BeatmapsetPackage.WriteFileCompletedArg arg) { e.Result = arg.Path; }; downloader.Download(); }
internal static void ScheduleAssetDownloads() { bool need = false; DownloadPackage dlp = new DownloadPackage("Assets", true); List <MinecraftAsset> needDl = new List <MinecraftAsset>(); assets.ForEach(a => { if (a.NeedsDownload()) { needDl.Add(a); Download dl = dlp.ScheduleDownload(a.Key, a.Url); dl.Downloaded += AssetDownloaded; need = true; } }); if (need) { DownloadManager.ScheduleDownload(dlp); } }
public static void SavePackage(this DownloadPackage package, string episodePath) { var formattedPath = GetFilePath(episodePath); IFormatter formatter = new BinaryFormatter(); var fileInfo = new FileInfo(formattedPath); if (!fileInfo.Exists) { fileInfo.Create().Dispose(); } lock (FileLock) { Stream serializedStream = null; try { serializedStream = new FileStream(formattedPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); formatter.Serialize(serializedStream, package); } finally { serializedStream?.Flush(); serializedStream?.Close(); serializedStream?.Dispose(); } } }
void bt_Click(object sender, System.Windows.RoutedEventArgs e) { if (changingVersion) { MessageBox.ShowDialog("Warning", "The version is currently being changed/downloaded! Cannot change now!"); } else { ChangeMCVersion cv = new ChangeMCVersion(); if (cv.ShowDialog() == true) { this.changingVersion = true; TinyMinecraftVersion prevVer = this.Version; this.Version = cv.version; try { Task.Factory.StartNew(delegate { if (!File.Exists(cv.version.FullVersion.BinaryPath)) { Download dl = cv.version.FullVersion.ScheduleJarDownload(); PluginAPI.PluginManager.onVersionDownload(dl); DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; cv.version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) DownloadManager.ScheduleDownload(dp); dl.WaitForComplete(); CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } else { CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } }); } catch (Exception ex) { MCM.Utils.MessageBox.ShowDialog("Error", "The selected version could not be changed because: " + ex.Message); this.Version = prevVer; (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); this.changingVersion = false; } } PluginManager.onChangeVersion(this); } }
internal static void StartMinecraft(Instance instance) { try { if (instance.Version == null) { App.InvokeAction(delegate { MCM.Utils.MessageBox.ShowDialog("Error", "Version not set in instance!"); }); return; } App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = false; }); App.Log("Waiting for downloads to finish..."); DownloadManager.WaitForAllMCRequire(); App.Log("Downloads should be finished!"); Process p = new Process(); string java = SettingsManager.GetSetting("javapath").data.ToString(); p.StartInfo.FileName = java; MinecraftUser user = null; MinecraftData.AppdataPath = instance.Version.FullVersion.LocalPath; App.InvokeAction(delegate { user = mainWindow.GetSelectedUser(); }); if (!File.Exists(instance.MinecraftJarFilePath)) { throw new Exception("No version selected"); } DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; instance.Version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if(dp.getDownloads().Count > 0) DownloadManager.ScheduleDownload(dp); App.Log("Waiting for minecraft download..."); DownloadManager.WaitForAllMCRequire(); p.StartInfo.Arguments = instance.GetStartArguments(user.username, user.password); App.Log("Starting Minecraft with arguments: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); p.StartInfo.UseShellExecute = false; p.EnableRaisingEvents = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.OutputDataReceived += (s, e) => { App.LogMinecraft(e.Data); }; p.ErrorDataReceived += (s, e) => { // No prefix since everything minecraft outputs seems to be an error App.LogMinecraft(e.Data); }; p.Exited += (s, e) => { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); Thread.Sleep(200); Syncronizer.SyncOptions(instance); Syncronizer.SyncServerlist(instance); PluginManager.onCloseMinecraft(instance,user); }; PluginManager.onStartMinecraft(instance, user); p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); } catch (Exception ex) { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); App.Log("An error occured while starting minecraft: " + ex.ToString()); } }
internal static void StartMinecraft(Instance instance) { try { if (instance.Version == null) { App.InvokeAction(delegate { MCM.Utils.MessageBox.ShowDialog("Error", "Version not set in instance!"); }); return; } App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = false; }); App.Log("Waiting for downloads to finish..."); DownloadManager.WaitForAllMCRequire(); App.Log("Downloads should be finished!"); Process p = new Process(); string java = SettingsManager.GetSetting("javapath").data.ToString(); p.StartInfo.FileName = java; MinecraftUser user = null; MinecraftData.AppdataPath = instance.Version.FullVersion.LocalPath; App.InvokeAction(delegate { user = mainWindow.GetSelectedUser(); }); if (!File.Exists(instance.MinecraftJarFilePath)) { throw new Exception("No version selected"); } DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; instance.Version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) { DownloadManager.ScheduleDownload(dp); } App.Log("Waiting for minecraft download..."); DownloadManager.WaitForAllMCRequire(); p.StartInfo.Arguments = instance.GetStartArguments(user.username, user.password); App.Log("Starting Minecraft with arguments: " + p.StartInfo.FileName + " " + p.StartInfo.Arguments); p.StartInfo.UseShellExecute = false; p.EnableRaisingEvents = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.OutputDataReceived += (s, e) => { App.LogMinecraft(e.Data); }; p.ErrorDataReceived += (s, e) => { // No prefix since everything minecraft outputs seems to be an error App.LogMinecraft(e.Data); }; p.Exited += (s, e) => { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); Thread.Sleep(200); Syncronizer.SyncOptions(instance); Syncronizer.SyncServerlist(instance); PluginManager.onCloseMinecraft(instance, user); }; PluginManager.onStartMinecraft(instance, user); p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); } catch (Exception ex) { App.InvokeAction(delegate { App.mainWindow.btn_startMinecraft.IsEnabled = true; }); App.Log("An error occured while starting minecraft: " + ex.ToString()); } }
private void OnDownloadResume(object sender, DownloadPackage e) { }
private void OnDownloadFileStarted(object sender, DownloadPackage e) { }
private void OnDownloadFileFail(object sender, DownloadPackage e) { }
void bt_Click(object sender, System.Windows.RoutedEventArgs e) { if (changingVersion) { MessageBox.ShowDialog("Warning", "The version is currently being changed/downloaded! Cannot change now!"); } else { ChangeMCVersion cv = new ChangeMCVersion(); if (cv.ShowDialog() == true) { this.changingVersion = true; TinyMinecraftVersion prevVer = this.Version; this.Version = cv.version; try { Task.Factory.StartNew(delegate { if (!File.Exists(cv.version.FullVersion.BinaryPath)) { Download dl = cv.version.FullVersion.ScheduleJarDownload(); PluginAPI.PluginManager.onVersionDownload(dl); DownloadPackage dp = new DownloadPackage("Libraries", true); dp.ShouldContinue = true; cv.version.FullVersion.Libraries.ForEach(l => { if (!File.Exists(l.Extractpath)) { l.ScheduleExtract(dp); } }); if (dp.getDownloads().Count > 0) { DownloadManager.ScheduleDownload(dp); } dl.WaitForComplete(); CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } else { CopyJar(); App.InvokeAction(delegate { (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); }); this.changingVersion = false; } }); } catch (Exception ex) { MCM.Utils.MessageBox.ShowDialog("Error", "The selected version could not be changed because: " + ex.Message); this.Version = prevVer; (App.mainWindow.listBox_instanceInfo.Items[0] as Label).Content = (this.Version == null ? "no version" : this.Version.Key); App.mainWindow.UpdateInstances(); this.changingVersion = false; } } PluginManager.onChangeVersion(this); } }