private Tasker DownloadFile(string url, string fileName)
        {
            var tasker = new Tasker(parentForm);

            tasker.AttachViews(new Tasks.TaskerTaskbar(), new Tasks.TaskerForm());
            tasker.SetStatusImage(Resources.sign_sync);
            tasker.SetTitle(Resources.DownloadingEllipsis);
            tasker.AddTask(WebClientTasks.DownloadFile(url, fileName));
            return(tasker);
        }
Example #2
0
        private IEnumerable <TaskFunc> GetItemDownloadTask(Repository.Repository.Item item)
        {
            var taskFuncs = new List <TaskFunc>();
            var tempPath  = TempHelpers.getUniqueTempPath();

            switch (item.Kind)
            {
            case Repository.Repository.ItemKind.Hmod:
                var modPath = Path.Combine(Program.BaseDirectoryExternal, "user_mods", item.FileName);
                if (File.Exists(modPath))
                {
                    File.Delete(modPath);
                }

                if (Directory.Exists(modPath))
                {
                    Directory.Delete(modPath, true);
                }

                if (item.Extract)
                {
                    taskFuncs.AddRange(new TaskFunc[] {
                        IOTasks.DirectoryCreate(modPath),
                        IOTasks.DirectoryCreate(tempPath),
                        WebClientTasks.DownloadFile(item.URL, Path.Combine(tempPath, item.FileName)),
                        ArchiveTasks.ExtractArchive(Path.Combine(tempPath, item.FileName), modPath),
                        IOTasks.DirectoryDelete(tempPath, true)
                    });
                }
                else
                {
                    taskFuncs.Add(WebClientTasks.DownloadFile(item.URL, modPath));
                }

                break;

            case Repository.Repository.ItemKind.Game:
                taskFuncs.AddRange(new TaskFunc[] {
                    IOTasks.DirectoryCreate(tempPath),
                    WebClientTasks.DownloadFile(item.URL, Path.Combine(tempPath, item.FileName)),
                    (Tasker tasker, object sync) =>
                    {
                        var taskerForms = tasker.GetSpecificViews <TaskerForm>().ToArray();
                        MainForm.StaticRef.AddGames(new string[] {
                            Path.Combine(tempPath, item.FileName)
                        }, parentForm: taskerForms.Length > 0 ? (Form)taskerForms[0] : (Form)parentForm);
                        return(Conclusion.Success);
                    },
                    IOTasks.DirectoryDelete(tempPath, true)
                });
                break;
            }
            return(taskFuncs);
        }
Example #3
0
        private Tasker DownloadFile(string url, string fileName)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            if (Directory.Exists(fileName))
            {
                Directory.Delete(fileName, true);
            }

            var tasker = new Tasker(parentForm);

            tasker.AttachViews(new Tasks.TaskerTaskbar(), new Tasks.TaskerForm());
            tasker.SetStatusImage(Resources.sign_sync);
            tasker.SetTitle(Resources.DownloadingEllipsis);
            tasker.AddTask(WebClientTasks.DownloadFile(url, fileName));
            return(tasker);
        }