コード例 #1
0
        private void ButtonUpdate_Click(object sender, RoutedEventArgs e)
        {
            DownloadWindow downloadWindow = new DownloadWindow(_latestRelease.assets[0].browser_download_url, _componentUpdated + ".zip");

            downloadWindow.Closed += afterDownload;
            downloadWindow.Show();
        }
コード例 #2
0
 private void Button_Click_5(object sender, RoutedEventArgs e)
 {
     try
     {
         for (int i = 0; i < gameList.Items.Count; i++)
         {
             if (File.Exists(_gameNames[i].IconName))
             {
                 continue;
             }
             var update =
                 new DownloadWindow(
                     "https://raw.githubusercontent.com/teknogods/TeknoParrotUIThumbnails/master/" +
                     _gameNames[i].IconName, _gameNames[i].IconName, false);
             update.ShowDialog();
         }
     }
     catch
     {
         // ignored
     }
 }
コード例 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LoadParrotData();
            //CreateConfigValue();

            foreach (var gameProfile in GameProfileLoader.GameProfiles)
            {
                ComboBoxItem item = new ComboBoxItem
                {
                    Content = gameProfile.GameName,
                    Tag     = gameProfile
                };

                GameListComboBox.Items.Add(item);

                if (_parrotData.SaveLastPlayed && gameProfile.GameName == _parrotData.LastPlayed)
                {
                    GameListComboBox.SelectedItem = item;
                }
            }

            new Thread(() =>
            {
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                Thread.CurrentThread.IsBackground    = true;
                try
                {
                    string contents;
                    using (var wc = new WebClient())
                        contents = wc.DownloadString("https://teknoparrot.com/api/version");
                    if (UpdateChecker.CheckForUpdate(GameVersion.CurrentVersion, contents))
                    {
                        if (MessageBox.Show(
                                $"There is a new version available: {contents} (currently using {GameVersion.CurrentVersion}). Would you like to download it?",
                                "New update!", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                        {
                            Thread.CurrentThread.IsBackground = false;
                            //Process.Start("https://teknoparrot.com");

                            Application.Current.Dispatcher.Invoke((Action) delegate {
                                Views.DownloadWindow update = new Views.DownloadWindow();
                                update.ShowDialog();
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignored
                }
            }).Start();

            if (_parrotData.UseDiscordRPC)
            {
                DiscordRPC.UpdatePresence(new DiscordRPC.RichPresence
                {
                    details       = "Main Menu",
                    largeImageKey = "teknoparrot",
                });
            }

            Title = "TeknoParrot UI " + GameVersion.CurrentVersion;
        }
コード例 #4
0
        private void ButtonUpdate_Click(object sender, RoutedEventArgs e)
        {
            downloadWindow         = new DownloadWindow(_latestRelease.assets[0].browser_download_url, $"{_componentUpdated.name} {onlineVersion}", true);
            downloadWindow.Closed += async(x, x2) =>
            {
                if (downloadWindow.data == null)
                {
                    return;
                }
                bool   isDone = false;
                bool   isUI   = _componentUpdated.name == "TeknoParrotUI";
                bool   isUsingFolderOverride = !string.IsNullOrEmpty(_componentUpdated.folderOverride);
                string destinationFolder     = isUsingFolderOverride ? _componentUpdated.folderOverride : _componentUpdated.name;

                if (!isUI)
                {
                    Directory.CreateDirectory(destinationFolder);
                }

                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    using (var memoryStream = new MemoryStream(downloadWindow.data))
                        using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                        {
                            foreach (var entry in zip.Entries)
                            {
                                var name = entry.FullName;

                                // directory
                                if (name.EndsWith("/"))
                                {
                                    name = isUsingFolderOverride ? Path.Combine(_componentUpdated.folderOverride, name) : name;
                                    Directory.CreateDirectory(name);
                                    Debug.WriteLine($"Updater directory entry: {name}");
                                    continue;
                                }

                                var dest = isUI ? name : Path.Combine(destinationFolder, name);
                                Debug.WriteLine($"Updater file: {name} extracting to: {dest}");

                                try
                                {
                                    if (File.Exists(dest))
                                    {
                                        File.Delete(dest);
                                    }
                                }
                                catch (UnauthorizedAccessException)
                                {
                                    // couldn't delete, just move for now
                                    File.Move(dest, dest + ".bak");
                                }

                                try
                                {
                                    using (var entryStream = entry.Open())
                                        using (var dll = File.Create(dest))
                                        {
                                            entryStream.CopyTo(dll);
                                        }
                                }
                                catch
                                {
                                    // ignore..?
                                }
                            }
                        }

                    isDone = true;
                    Debug.WriteLine("Zip extracted");
                }).Start();

                while (!isDone)
                {
                    Debug.WriteLine("Still extracting files..");
                    await Task.Delay(25);
                }
                if (_componentUpdated.name == "TeknoParrotUI")
                {
                    if (MessageBoxHelper.InfoYesNo(Properties.Resources.UpdaterRestart))
                    {
                        string[] psargs = Environment.GetCommandLineArgs();
                        System.Diagnostics.Process.Start(Application.ResourceAssembly.Location, psargs[0]);
                        Application.Current.Shutdown();
                    }
                    else
                    {
                        Application.Current.Shutdown();
                    }
                }

                MessageBoxHelper.InfoOK(string.Format(Properties.Resources.UpdaterSuccess, _componentUpdated.name, onlineVersion));

                this.Close();
            };
            downloadWindow.Show();
        }
コード例 #5
0
        private async void buttonDl_Click(object sender, RoutedEventArgs e)
        {
            /*
             * Ok this is the dumb part, writing steps to remind myself how this is meant to work..
             * 1. download zip from gh
             * 2. extract zip in game folder root
             * 3. find all xdelta files
             * 4. patch all files
             * 5. ???
             * 6. profit
             *
             * i don't think normal downloadcontrol will work for this one, it's more tailored for updates
             */


            string gameRoot = Path.GetDirectoryName(_thisGame.GamePath);

            if (Directory.Exists(gameRoot))
            {
                var patchZip = new DownloadWindow(_zipUrl, _modName, true);

                patchZip.Closed += (x, x2) =>
                {
                    if (patchZip.data == null)
                    {
                        return;
                    }
                    using (var memoryStream = new MemoryStream(patchZip.data))
                        using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                        {
                            foreach (var entry in zip.Entries)
                            {
                                //remove TeknoParrotUIThumbnails-master/
                                var name = entry.FullName.Substring(entry.FullName.IndexOf('/') + 1);
                                if (string.IsNullOrEmpty(name))
                                {
                                    continue;
                                }
                                Debug.WriteLine($"Extracting {name}");

                                try
                                {
                                    using (var entryStream = entry.Open())
                                        using (var dll = File.Create(gameRoot + "\\" + name))
                                        {
                                            entryStream.CopyTo(dll);
                                            entryStream.Close();
                                        }

                                    string xDeltaFile = gameRoot + "\\" + name;
                                    if (name.Contains(".xdeltanew"))
                                    {
                                        byte[] patchedFile = XDelta3.ApplyPatch(File.ReadAllBytes(xDeltaFile), new byte[0]);
                                        File.WriteAllBytes(xDeltaFile.Replace(".xdeltanew", ""), patchedFile);
                                    }
                                    else
                                    {
                                        byte[] patchedFile = XDelta3.ApplyPatch(File.ReadAllBytes(xDeltaFile),
                                                                                File.ReadAllBytes(xDeltaFile.Replace(".xdelta", "")));
                                        File.WriteAllBytes(xDeltaFile.Replace(".xdelta", ""), patchedFile);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                    // ignore..?
                                }
                            }
                        }

                    isDone = true;
                };
                patchZip.Show();
                await isItDone();

                Application.Current.Windows.OfType <MainWindow>().Single()
                .ShowMessage("Mod downloaded and installed successfully!");
                buttonDl.IsEnabled = false;
                _modMenu.installedGUIDs.Add(Path.GetFileNameWithoutExtension(_zipUrl));
                WriteToXmlFile("InstalledMods.xml", _modMenu.installedGUIDs, false);
            }
            else
            {
                Application.Current.Windows.OfType <MainWindow>().Single()
                .ShowMessage("Game directory doesn't exist...");
            }
        }
コード例 #6
0
        private void BtnDownloadMissingIcons(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("This will download every missing icon for TeknoParrot. The file is around 50 megabytes. Are you sure you want to continue?", "Warning",
                                MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                try
                {
                    var icons = new DownloadWindow("https://github.com/teknogods/TeknoParrotUIThumbnails/archive/master.zip", "TeknoParrot Icons", true);
                    icons.Closed += (x, x2) =>
                    {
                        if (icons.data == null)
                        {
                            return;
                        }
                        using (var memoryStream = new MemoryStream(icons.data))
                            using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                            {
                                foreach (var entry in zip.Entries)
                                {
                                    //remove TeknoParrotUIThumbnails-master/
                                    var name = entry.FullName.Substring(entry.FullName.IndexOf('/') + 1);
                                    if (string.IsNullOrEmpty(name))
                                    {
                                        continue;
                                    }

                                    if (File.Exists(name))
                                    {
                                        Debug.WriteLine($"Skipping already existing icon {name}");
                                        continue;
                                    }

                                    // skip readme and folder entries
                                    if (name == "README.md" || name.EndsWith("/"))
                                    {
                                        continue;
                                    }

                                    Debug.WriteLine($"Extracting {name}");

                                    try
                                    {
                                        using (var entryStream = entry.Open())
                                            using (var dll = File.Create(name))
                                            {
                                                entryStream.CopyTo(dll);
                                            }
                                    }
                                    catch
                                    {
                                        // ignore..?
                                    }
                                }
                            }
                    };
                    icons.Show();
                }
                catch
                {
                    // ignored
                }
            }
        }
コード例 #7
0
        private void ButtonUpdate_Click(object sender, RoutedEventArgs e)
        {
            downloadWindow         = new DownloadWindow(_latestRelease.assets[0].browser_download_url, $"{_componentUpdated.name} {onlineVersion}", true);
            downloadWindow.Closed += (x, x2) =>
            {
                if (downloadWindow.data == null)
                {
                    return;
                }

                bool   isUI = _componentUpdated.name == "TeknoParrotUI";
                bool   isUsingFolderOverride = !string.IsNullOrEmpty(_componentUpdated.folderOverride);
                string destinationFolder     = isUsingFolderOverride ? _componentUpdated.folderOverride : _componentUpdated.name;

                if (!isUI)
                {
                    Directory.CreateDirectory(destinationFolder);
                }

                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    using (var memoryStream = new MemoryStream(downloadWindow.data))
                        using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read))
                        {
                            foreach (var entry in zip.Entries)
                            {
                                var name = entry.FullName;

                                // directory
                                if (name.EndsWith("/"))
                                {
                                    name = isUsingFolderOverride ? Path.Combine(_componentUpdated.folderOverride, name) : name;
                                    Directory.CreateDirectory(name);
                                    Debug.WriteLine($"Updater directory entry: {name}");
                                    continue;
                                }

                                var dest = isUI ? name : Path.Combine(destinationFolder, name);
                                Debug.WriteLine($"Updater file: {name} extracting to: {dest}");

                                try
                                {
                                    if (File.Exists(dest))
                                    {
                                        File.Delete(dest);
                                    }
                                }
                                catch (UnauthorizedAccessException)
                                {
                                    // couldn't delete, just move for now
                                    File.Move(dest, dest + ".bak");
                                }

                                try
                                {
                                    using (var entryStream = entry.Open())
                                        using (var dll = File.Create(dest))
                                        {
                                            entryStream.CopyTo(dll);
                                        }
                                }
                                catch
                                {
                                    // ignore..?
                                }
                            }
                        }
                }).Start();

                if (_componentUpdated.name == "TeknoParrotUI")
                {
                    if (MessageBox.Show(
                            $"Would you like to restart me to finish the update? Otherwise, I will close TeknoParrotUi for you to reopen.",
                            "Update Complete", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                    {
                        string[] psargs = Environment.GetCommandLineArgs();
                        System.Diagnostics.Process.Start(Application.ResourceAssembly.Location, psargs[0]);
                        Application.Current.Shutdown();
                    }
                    else
                    {
                        Application.Current.Shutdown();
                    }
                }

                MessageBox.Show($"Sucessfully updated {_componentUpdated.name} to {onlineVersion}", "TeknoParrot Updater", MessageBoxButton.OK, MessageBoxImage.Information);

                this.Close();
            };
            downloadWindow.Show();
        }