Exemplo n.º 1
0
 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);
            }
        }
Exemplo n.º 3
0
 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);
        }
Exemplo n.º 5
0
 public void ScheduleExtract(DownloadPackage pkg)
 {
     if (!File.Exists(Extractpath))
     {
         Download dl = pkg.ScheduleDownload(this.Name, this.Url);
         ApplyDlStuff(dl);
     }
 }
Exemplo n.º 6
0
        internal void CallDownloadResume(DownloadPackage package)
        {
            if (OnDownloadResume == null)
            {
                return;
            }

            OnDownloadResume(this, package);
        }
Exemplo n.º 7
0
        internal void CallDownloadFileFail(DownloadPackage package)
        {
            if (OnDownloadFileFail == null)
            {
                return;
            }

            OnDownloadFileFail(this, package);
        }
Exemplo n.º 8
0
        internal void CallDownloadFileComplete(DownloadPackage package)
        {
            if (OnDownloadFileComplete == null)
            {
                return;
            }

            OnDownloadFileComplete(this, package);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 11
0
        public Manager(IDownloadHelper downloadHelper)
        {
            this._downloadHelper = downloadHelper;

            _validator       = new Validator();
            _efManager       = new EFManager();
            _mailManager     = new MailManager();
            _linkManager     = new LinkManager();
            _downloadPackage = new DownloadPackage();
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
 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);
 }
Exemplo n.º 15
0
        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]);
            }
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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);
            }
        }
Exemplo n.º 18
0
        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;
        }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
        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();
                }
            }
        }
Exemplo n.º 22
0
        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);
            }
        }
Exemplo n.º 23
0
        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());
            }
        }
Exemplo n.º 24
0
        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());
            }
        }
Exemplo n.º 25
0
 private void OnDownloadResume(object sender, DownloadPackage e)
 {
 }
Exemplo n.º 26
0
 private void OnDownloadFileStarted(object sender, DownloadPackage e)
 {
 }
Exemplo n.º 27
0
 private void OnDownloadFileFail(object sender, DownloadPackage e)
 {
 }
Exemplo n.º 28
0
        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);
            }
        }