Example #1
0
        public async void repairButtonClick(object sender, RoutedEventArgs e)
        {
            repairButton.IsEnabled = false;
            startButton.IsEnabled  = false;
            ObsoleteFiles          = await ObsoleteFileFinder.SearchObsoleteAsync(RemoteFiles);

            if (ObsoleteFiles.Count > 0)
            {
                startButton.IsEnabled = false;
                _updateObsoleteFiles();
            }
            else
            {
                repairButton.IsEnabled = true;
                startButton.IsEnabled  = true;
            }
        }
Example #2
0
        public PatcherWindow(WebClient client, ObsoleteFileFinder obsoleteFileFinder, List <PatchFile> remoteFiles, List <PatchFile> obsoleteFiles)
        {
            InitializeComponent();
            Client             = client;
            ObsoleteFileFinder = obsoleteFileFinder;
            RemoteFiles        = remoteFiles;
            ObsoleteFiles      = obsoleteFiles;

            startButton.Click  += startButtonClick;
            repairButton.Click += repairButtonClick;

            closeButton.Click   += closeButtonClick;
            minifyButton.Click  += minButtonClick;
            discordButton.Click += discordButtonClick;

            this.MouseDown += OnMouseDown;

            Initialize();
        }
        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();
            }
        }