コード例 #1
0
 public UpdaterDownloadListener(UpdateWindow w, HTTPDownloader d)
 {
     window     = w;
     downloader = d;
     d.setProgressChangedEventHandler(new DownloadProgressChangedEventHandler(onProgressChanged));
     d.setNewFileDownloadingEventHandler(new NewFileDownloadingEventHandler(OnNewFile));
     d.setAllFileDownloadedEventHandler(new AllFileDownloadedEventHandler(OnAllFile));
 }
コード例 #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            m = new Mutex(false, "rom2updater");
            if (!m.WaitOne(0, false))
            {
                Application.Current.Shutdown();
            }
            if (IsProcessOpen("warlords.patcher.exe"))
            {
                Application.Current.Shutdown();
            }

            //Da fare gestione config
            string updateIndexFileName = "metaFiles/UpdaterIndex";
            string cleanerFileName     = "metaFiles/UpdateCleaner";
            string baseAddress         = "http://patcher.metin2warlords.net/";
            string argument            = "nonhofantasia";

            UpdateWindow window = new UpdateWindow();

            window.Show();
            WebClient client = new WebClient();

            client.BaseAddress = baseAddress;

            string s = client.DownloadString(updateIndexFileName);
            string c = client.DownloadString(cleanerFileName);


            CleanerExtractor ce          = new CleanerExtractor(c);
            List <PatchFile> toCleanFile = ce.extract();

            foreach (PatchFile f in toCleanFile)
            {
                string path = Path.Combine(f.BasePath, f.Name);
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                    File.Delete(path);
                }
            }
            PipeDelimitedFileManifestParser p = new PipeDelimitedFileManifestParser(s);
            ObsoleteFileFinder scanner        = new ObsoleteFileFinder(p);

            scanner.Search();
            List <PatchFile> toUpdateFiles = scanner.getToUpdateFiles();
            List <PatchFile> sourceFiles   = scanner.getSourceFiles();
            string           exeName       = sourceFiles[0].Name;
            BackgroundWorker bw            = new BackgroundWorker();

            if (toUpdateFiles.Count > 0)
            {
                HTTPDownloader          downloader = new HTTPDownloader(toUpdateFiles, client, "sourceUpdater/");
                UpdaterDownloadListener listener   = new UpdaterDownloadListener(window, downloader);
                downloader.allFileDownloaded += (object ss) =>
                {
                    System.Diagnostics.Process.Start(exeName, argument);
                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        window.Close();
                    }
                                                                   ));
                };

                bw.DoWork += (object se, DoWorkEventArgs es) =>
                {
                    downloader.startDownload();
                };
                bw.RunWorkerAsync();
            }


            if (bw.IsBusy == false)
            {
                System.Diagnostics.Process.Start(exeName, argument);
                window.Close();
            }
        }