예제 #1
0
        public void BeginProcess(ProjectLoadForm.UpdateCallbacks callbacks)
        {
            string tmpDir = IOUtils.CreateTemporaryDirectory();
            string tmpFile = tmpDir == null ? "github.zip" : Path.Combine(tmpDir, "github.zip");

            DownloadProgressChanged = (sender, args) => {
                callbacks.UpdateProgress(args.TotalBytesToReceive == -1 ? -1 : args.ProgressPercentage);
                callbacks.UpdateDataLabel(args.TotalBytesToReceive == -1 ? (args.BytesReceived/1024)+" kB" : (args.BytesReceived/1024)+" / "+(args.TotalBytesToReceive/1024)+" kB");
            };

            DownloadFinished = (sender, args) => {
                if (args.Cancelled){ // apparently randomly throws IOException and ObjectDisposedException... WHAT THE F**K .NET
                    if (CancelFinish != null){
                        CancelFinish();
                    }

                    return;
                }

                if (args.Error != null){
                    callbacks.UpdateInfoLabel(Lang.Get["LoadGitHubDownloadError"]);
                    return;
                }

                callbacks.UpdateInfoLabel(Lang.Get["LoadGitHubExtractingRepo"]);

                ZipArchive archive = new ZipArchive(tmpFile);

                dlRepoCancel = archive.ExtractAsync(path => {
                    callbacks.OnReady(new FileSearch(new string[]{ path }));
                    archive.DeleteAndDispose();
                });
            };

            switch(DownloadRepositoryZip(tmpFile)){
                case DownloadStatus.Started:
                    callbacks.UpdateInfoLabel(Lang.Get["LoadGitHubDownloadingRepo"]);
                    break;

                case DownloadStatus.NoInternet:
                    callbacks.UpdateInfoLabel(Lang.Get["LoadGitHubNoInternet"]);
                    break;

                case DownloadStatus.NoConnection:
                    callbacks.UpdateInfoLabel(Lang.Get["LoadGitHubNoEstablishedConnection"]);
                    break;
            }
        }