Ejemplo n.º 1
0
        public async void Download(string line, bool running)
        {
            if (ParseProtocol(line))
            {
                if (await GetData())
                {
                    DownloadWindow downloadWindow = new DownloadWindow(response);
                    downloadWindow.ShowDialog();
                    downloadWindow.Activate();
                    if (downloadWindow.YesNo)
                    {
                        await DownloadFile(URL_TO_ARCHIVE, fileName, new Progress <DownloadProgress>(ReportUpdateProgress),
                                           CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));
                        await ExtractFile($@"{assemblyLocation}\Downloads\{fileName}", response.Game.Replace(" (PC)", ""));

                        if (File.Exists($@"{assemblyLocation}\refresh.aem"))
                        {
                            FileIOWrapper.Delete($@"{assemblyLocation}\refresh.aem");
                        }
                        FileIOWrapper.WriteAllText($@"{assemblyLocation}\refresh.aem", response.Game.Replace(" (PC)", ""));
                    }
                }
            }
            if (running)
            {
                Environment.Exit(0);
            }
        }
Ejemplo n.º 2
0
        public async void BrowserDownload(GameBananaRecord record, GameFilter game)
        {
            var gameName = "";

            switch (game)
            {
            case GameFilter.P3:
                gameName = "Persona 3 FES";
                break;

            case GameFilter.P4G:
                gameName = "Persona 4 Golden";
                break;

            case GameFilter.P5:
                gameName = "Persona 5";
                break;

            case GameFilter.P5S:
                gameName = "Persona 5 Strikers";
                break;
            }
            DownloadWindow downloadWindow = new DownloadWindow(record);

            downloadWindow.ShowDialog();
            if (downloadWindow.YesNo)
            {
                string downloadUrl = null;
                string fileName    = null;
                if (record.Files.Count == 1)
                {
                    downloadUrl = record.Files[0].DownloadUrl;
                    fileName    = record.Files[0].FileName;
                }
                else if (record.Files.Count > 1)
                {
                    UpdateFileBox fileBox = new UpdateFileBox(record.Files, record.Title);
                    fileBox.Activate();
                    fileBox.ShowDialog();
                    downloadUrl = fileBox.chosenFileUrl;
                    fileName    = fileBox.chosenFileName;
                }
                if (downloadUrl != null && fileName != null)
                {
                    await DownloadFile(downloadUrl, fileName, new Progress <DownloadProgress>(ReportUpdateProgress),
                                       CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Token));

                    if (!cancelled)
                    {
                        await ExtractFile($@"{assemblyLocation}\Downloads\{fileName}", gameName);

                        if (File.Exists($@"{assemblyLocation}\refresh.aem"))
                        {
                            FileIOWrapper.Delete($@"{assemblyLocation}\refresh.aem");
                        }
                        FileIOWrapper.WriteAllText($@"{assemblyLocation}\refresh.aem", gameName);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task ExtractFile(string file, string game)
        {
            await Task.Run(() =>
            {
                if (Path.GetExtension(file).ToLower() == ".7z" || Path.GetExtension(file).ToLower() == ".rar" || Path.GetExtension(file).ToLower() == ".zip")
                {
                    Directory.CreateDirectory($@"{assemblyLocation}\temp");
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.CreateNoWindow   = true;
                    startInfo.FileName         = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\7z\7z.exe";
                    if (!FileIOWrapper.Exists(startInfo.FileName))
                    {
                        MessageBox.Show($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
                    startInfo.UseShellExecute = false;
                    startInfo.Arguments       = $@"x -y ""{file}"" -o""{assemblyLocation}\temp""";
                    using (Process process = new Process())
                    {
                        process.StartInfo = startInfo;
                        process.Start();
                        process.WaitForExit();
                    }
                    setAttributesNormal(new DirectoryInfo($@"{assemblyLocation}\temp"));
                    foreach (var folder in Directory.GetDirectories($@"{assemblyLocation}\temp", "*", SearchOption.AllDirectories).Where(x => File.Exists($@"{x}\Package.xml") || File.Exists($@"{x}\Mod.xml")))
                    {
                        string path = $@"{assemblyLocation}\Packages\{game}\{Path.GetFileName(folder)}";
                        int index   = 2;
                        while (Directory.Exists(path))
                        {
                            path   = $@"{assemblyLocation}\Packages\{game}\{Path.GetFileName(folder)} ({index})";
                            index += 1;
                        }
                        MoveDirectory(folder, path);
                    }
                    var packgeSetup = Directory.GetFiles($@"{assemblyLocation}\temp", "*Packages.xml", SearchOption.AllDirectories);
                    if (packgeSetup.Length > 0)
                    {
                        Directory.CreateDirectory($@"{assemblyLocation}\Config\temp");
                        foreach (var xml in packgeSetup)
                        {
                            File.Copy(xml, $@"{assemblyLocation}\Config\temp\{Path.GetFileName(xml)}", true);
                        }
                    }
                    FileIOWrapper.Delete(file);
                }
                else
                {
                    MessageBox.Show($"{file} isn't a .zip, .7z, or .rar, couldn't extract...", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                if (Directory.Exists($@"{assemblyLocation}\temp"))
                {
                    Directory.Delete($@"{assemblyLocation}\temp", true);
                }
            });
        }
Ejemplo n.º 4
0
        private void MoveDirectory(string source, string target)
        {
            var sourcePath = source.TrimEnd('\\', ' ');
            var targetPath = target.TrimEnd('\\', ' ');
            var files      = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories)
                             .GroupBy(s => Path.GetDirectoryName(s));

            foreach (var folder in files)
            {
                var targetFolder = folder.Key.Replace(sourcePath, targetPath);
                Directory.CreateDirectory(targetFolder);
                foreach (var file in folder)
                {
                    var targetFile = Path.Combine(targetFolder, Path.GetFileName(file));
                    if (FileIOWrapper.Exists(targetFile))
                    {
                        FileIOWrapper.Delete(targetFile);
                    }
                    FileIOWrapper.Move(file, targetFile);
                }
            }
            Directory.Delete(source, true);
        }