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();
        }
Example #2
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();
        }
Example #3
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
                }
            }
        }
        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...");
            }
        }
Example #5
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();
        }