Пример #1
0
        protected override async Task DownloadImplementation()
        {
            string[] roots = Directory.GetDirectories(Directory.GetCurrentDirectory() + "\\" + Properties.Settings.Default.GameDirectory);
            if (roots.Length > 1)
            {
                throw new DirectoryNotFoundException(message: string.Format("Multiple roots:\n{0}", string.Join("\n", roots)));
            }
            if (roots.Length == 0)
            {
                ShowError("There are no files inside your installation directory.");
                throw new DirectoryNotFoundException();
            }
            string root = roots[0];

            foreach (string file in oldPath)
            {
                var fileInfo = new FileInfo(root + "\\" + file);
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
            }
            double n_file     = newPath.Count;
            int    downloaded = 0;

            using (var webClient = new WebClient())
            {
                foreach (string file in newPath)
                {
                    string url = this.url + file;
                    System.Diagnostics.Debug.WriteLine(file);
                    System.Diagnostics.Debug.WriteLine(root + "\\" + file.Replace("/", "\\"));
                    System.Diagnostics.Debug.WriteLine(url);
                    var fileInfo = new FileInfo(root + "\\" + file.Replace("/", "\\"));
                    if (fileInfo.Exists)
                    {
                        fileInfo.Delete();
                    }
                    if (fileInfo.Directory.Exists == false)
                    {
                        fileInfo.Directory.Create();
                    }
                    try
                    {
                        await webClient.DownloadFileTaskAsync(url, root + "\\" + file.Replace("/", "\\"));
                    }
                    catch (WebException)
                    {
                        // The file is in newPath but it has been mooved or deleted in a future commit, so it cannot be downloaded, just do nothing
                    }
                    downloaded++;
                    ShowProgress(downloaded / n_file * 100);
                }
            }
            Properties.Settings.Default.Version       = (await handler.GetLatestRelease()).Tag;
            Properties.Settings.Default.CurrentCommit = (await handler.GetLatestRelease()).Commit;
            Properties.Settings.Default.Save();
            PhpManager.UpdateVersion((await handler.GetLatestRelease()).Tag);
        }
Пример #2
0
        /// <summary>
        /// Search for program executable and launch it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LaunchGame(object sender, RoutedEventArgs e)
        {
            var     executable = Properties.Resources.Executable;
            Process process    = new Process();

            foreach (string f in Directory.EnumerateFiles(Directory.GetCurrentDirectory() + "\\" + FILE_NAME, executable, SearchOption.AllDirectories))
            {
                process.StartInfo.FileName = f;
                process.Start();
                PhpManager.UpdateVersion(Properties.Settings.Default.Version);
                CloseWindow(sender, e);
                return;
            }
            PhpManager.ReportError(String.Format("{0} not found in {1}", executable, Directory.GetCurrentDirectory() + "\\" + FILE_NAME));
            MessageBox.Show(String.Format(Properties.Langs.Lang.exe_not_found, executable), Properties.Langs.Lang.warning);
        }