private void cboGameSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            string NullDir = Launcher.rootDir + "nulldc-1-0-4-en-win\\";
            string RomDir  = NullDir + "roms\\";

            bool ReferenceFound = false;

            if (Launcher.GamesJson != null && Launcher.GamesJson.Count > 0)
            {
                Launcher.Game SelectedGame = Launcher.GamesJson.Where(g => g.Name == cboGameSelect.Text).FirstOrDefault();
                if (SelectedGame != null)
                {
                    ReferenceFound = (SelectedGame.ReferenceUrl != null);
                }


                if ((string)cboGameSelect.Text != "" && (string)cboGameSelect.SelectedValue == "" && ReferenceFound)
                {
                    btnOffline.Enabled = false;
                    btnJoin.Enabled    = false;
                    btnHost.Enabled    = false;
                    DialogResult dialogResult = MessageBox.Show(
                        $"{cboGameSelect.Text} not installed.\nWould you like to retrieve it?",
                        "Missing ROM",
                        MessageBoxButtons.YesNo);
                    switch (dialogResult)
                    {
                    case (DialogResult.Yes):
                        Program.ShowConsoleWindow();
                        Console.Clear();
                        NetworkQuery.DownloadReferenceUrl(SelectedGame);
                        Program.HideConsoleWindow();
                        var previous = cboGameSelect.SelectedIndex;
                        ReloadRomList();
                        cboGameSelect.SelectedIndex = previous;
                        break;

                    case (DialogResult.No):
                        break;
                    }
                }
                else if (cboGameSelect.SelectedValue != null)
                {
                    btnOffline.Enabled    = true;
                    btnJoin.Enabled       = true;
                    btnHost.Enabled       = true;
                    Launcher.SelectedGame = cboGameSelect.SelectedValue.ToString();
                }
            }
        }
Пример #2
0
        private void DragLoadControl_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                string path     = files[0];
                string destpath = Launcher.rootDir + "nulldc-1-0-4-en-win\\";

                if (Path.GetExtension(path).Equals(".bin"))
                {
                    destpath += "data\\" + Path.GetFileName(files[0]);
                    if (File.Exists(destpath))
                    {
                        File.SetAttributes(destpath, FileAttributes.Normal);
                    }
                    if (path == destpath)
                    {
                        MessageBox.Show("Your file is already in the correct place, you silly billy.");
                        return;
                    }
                    else
                    {
                        lblDragInfo.Text = "Copying BIN...";
                        File.Copy(path, destpath, true);
                        File.SetAttributes(destpath, FileAttributes.ReadOnly);
                        lblDragInfo.Text = $"BIN copied to {Launcher.ExtractRelativePath(destpath)}";
                    }
                }
                else if (Path.GetExtension(path).Equals(".qjc"))
                {
                    lblDragInfo.Text = "Copying QJC...";
                    destpath        += "qkoJAMMA\\" + Path.GetFileName(files[0]);
                    if (File.Exists(destpath))
                    {
                        File.SetAttributes(destpath, FileAttributes.Normal);
                    }
                    File.Copy(path, destpath, true);
                    lblDragInfo.Text = $"QJC copied to {Launcher.ExtractRelativePath(destpath)}";
                }
                else if (Path.GetExtension(path).Equals(".qkc"))
                {
                    lblDragInfo.Text = "Copying QKC...";
                    destpath        += "qkoJAMMA\\" + Path.GetFileName(files[0]);
                    if (File.Exists(destpath))
                    {
                        File.SetAttributes(destpath, FileAttributes.Normal);
                    }
                    File.Copy(path, destpath, true);
                    lblDragInfo.Text = $"QKC copied to {Launcher.ExtractRelativePath(destpath)}";
                }
                else if (Path.GetFileName(path) == "nullDC.cfg")
                {
                    lblDragInfo.Text = "Copying CFG...";
                    destpath        += Path.GetFileName(files[0]);
                    if (File.Exists(destpath))
                    {
                        File.SetAttributes(destpath, FileAttributes.Normal);
                    }
                    File.Copy(path, destpath, true);
                    lblDragInfo.Text = $"nullDC.cfg copied to {Launcher.ExtractRelativePath(destpath)}. Restart to restore defaults.";
                }
                else if (Path.GetExtension(path).Equals(".zip"))
                {
                    bool          zipHasEntry    = false;
                    var           folderName     = Path.GetFileNameWithoutExtension(files[0]);
                    Launcher.Game GamesJsonEntry = null;
                    if (Launcher.GamesJson != null)
                    {
                        try
                        {
                            GamesJsonEntry = Launcher.GamesJson.Where(g => g.Name == folderName).First();
                            if (GamesJsonEntry != null && GamesJsonEntry.Assets.Count() > 0)
                            {
                                zipHasEntry = true;
                            }
                        }
                        catch (Exception) { };
                    }

                    destpath += "roms\\" + folderName;
                    Directory.CreateDirectory(destpath);
                    lblDragInfo.Text = "Extracting ROM...";
                    if (File.Exists(path))
                    {
                        ZipArchive archive = ZipFile.OpenRead(path);
                        if (zipHasEntry)
                        {
                            Program.ShowConsoleWindow();
                            Console.Clear();
                        }
                        foreach (ZipArchiveEntry entry in archive.Entries)
                        {
                            Launcher.Asset asset = null;

                            if (GamesJsonEntry != null)
                            {
                                asset = GamesJsonEntry.Assets.Where(a => a.Name == entry.Name).First();
                            }

                            if (zipHasEntry)
                            {
                                entry.ExtractToFile(Path.Combine(destpath, asset.LocalName()), true);
                                var verifiedString = asset.VerifyFile(Path.Combine(destpath, asset.LocalName()));
                                Console.WriteLine(verifiedString);
                            }
                            else
                            {
                                entry.ExtractToFile(Path.Combine(destpath, entry.FullName), true);
                            }
                        }
                        if (zipHasEntry)
                        {
                            Console.WriteLine("\nPress any key to continue.");
                            Console.ReadKey();
                            Program.HideConsoleWindow();
                        }
                    }
                    lblDragInfo.Text = $"Rom Extracted to {Launcher.ExtractRelativePath(destpath)}";
                }
            }
        }
Пример #3
0
        public static void DownloadReferenceUrl(Launcher.Game game, bool clearCache = true)
        {
            string displayName;

            if (game.Name.Length > 0)
            {
                displayName = game.Name;
            }
            else
            {
                displayName = game.ID;
            }

            string workingDir = "";

            if (game.Root == "roms" || game.Root == "data")
            {
                workingDir = Path.Combine(Launcher.rootDir, "nulldc-1-0-4-en-win", game.Root);
            }
            else
            {
                Console.WriteLine("no valid root found in reference entry");
                return;
            }
            var di = new DirectoryInfo(workingDir);

            di.Attributes |= FileAttributes.Normal;
            var zipPath = Path.Combine(workingDir, $"{Path.GetFileNameWithoutExtension(game.ReferenceUrl)}.zip");

            if (!File.Exists(zipPath))
            {
                Console.WriteLine($"Downloading {displayName}...");
                var referenceUri = new Uri(game.ReferenceUrl);
                if (referenceUri.Host == "mega.nz")
                {
                    MegaApiClient client = new MegaApiClient();
                    client.LoginAnonymous();

                    INodeInfo node = client.GetNodeFromLink(referenceUri);

                    Console.WriteLine($"Downloading {node.Name}");
                    client.DownloadFile(referenceUri, zipPath);

                    client.Logout();
                }
                else
                {
                    using (WebClient client = new WebClient())
                    {
                        Console.WriteLine($"Downloading {Path.GetFileName(referenceUri.LocalPath)}");
                        client.DownloadFile(referenceUri,
                                            zipPath);
                    }
                }
                Console.WriteLine($"Download Complete");
            }

            Console.WriteLine($"Extracting...\n");

            string extractPath;

            if (game.Root == "roms")
            {
                extractPath = Path.Combine(workingDir, displayName);
                Directory.CreateDirectory(extractPath);
            }
            else
            {
                extractPath = workingDir;
            }

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                List <Launcher.Asset> files = game.Assets;
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    try
                    {
                        var fileEntry = files.Where(f => f.Name == entry.Name).First();
                        if (fileEntry != null)
                        {
                            var destinationFile = Path.Combine(extractPath, fileEntry.LocalName());
                            entry.ExtractToFile(destinationFile, true);
                            Console.WriteLine(fileEntry.VerifyFile(destinationFile));
                        }
                    }
                    catch (Exception) { }
                }
            }

            if (clearCache)
            {
                File.Delete(zipPath);
            }

            Console.WriteLine($"\nPress any key to continue.");
            Console.ReadKey();
        }