Exemplo n.º 1
0
        public static void LoadGFileFromPak(AAPak pak, string fileName)
        {
            if ((pak == null) || (!pak.isOpen) || !pak.FileExists(fileName))
            {
                return;
            }

            var lines = new List <string>();

            using (var fs = pak.ExportFileAsStream(fileName))
            {
                using (var sr = new StreamReader(fs))
                {
                    while (!sr.EndOfStream)
                    {
                        lines.Add(sr.ReadLine());
                    }
                }
            }
            var gf = ConvertGFileStringList(lines);

            foreach (var gl in gf)
            {
                if (GFileVars.ContainsKey(gl.Key))
                {
                    GFileVars.Remove(gl.Key);
                }
                GFileVars.Add(gl.Key, gl.Value);
            }
        }
Exemplo n.º 2
0
        private bool HandleArgs()
        {
            bool showHelp = false;

            var args = Environment.GetCommandLineArgs();

            for (int i = 1; i < args.Length; i++)
            {
                var    larg    = args[i].ToLower();
                string nextArg = "";
                if (i < args.Length - 1)
                {
                    nextArg = args[i + 1];
                }


                switch (larg)
                {
                case "-m":
                    // Mod source
                    ModPakFileName = nextArg;
                    i++;
                    break;

                case "-g":
                    // Game_Pak
                    GamePakFileName = nextArg;
                    i++;
                    break;

                case "-r":
                    // restore pak
                    RestorePakFileName = nextArg;
                    i++;
                    break;

                case "-?":
                case "-h":
                case "-help":
                case "/?":
                case "/h":
                case "/help":
                    // Help
                    showHelp = true;
                    break;
                }
            }


            if (showHelp)
            {
                Hide();
                MessageBox.Show(helpText, "AAMod - Command-Line Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            // if nothing specified, try self
            if (ModPakFileName == string.Empty)
            {
                ModPakFileName = Application.ExecutablePath;
                Text           = DefaultTitle + " - Self-Extractor - " + Path.GetFileNameWithoutExtension(Application.ExecutablePath);
            }
            else
            {
                Text = DefaultTitle + " - " + ModPakFileName;
            }

            if (!File.Exists(ModPakFileName))
            {
                MessageBox.Show("Mod-file not found\n" + ModPakFileName, "aamod Open Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            if (!modpak.OpenPak(ModPakFileName, true))
            {
                if (ModPakFileName == Application.ExecutablePath)
                {
                    // show a different error if you tried to open it without any parameters and tried to use the exe as a pak and failed
                    Visible = false;
                    MessageBox.Show("This program cannot be used as a stand-alone program.\n" +
                                    "You either need to provide command-line arguments or this file needs to be generated by AAPakEditor to contain pak information.\n\n" +
                                    "Use -? to get a list of possible arguments.", "AAMod Open Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    MessageBox.Show("Failed to open mod-file for reading\n" + ModPakFileName, "aamod Open Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                return(false);
            }


            if (modpak.FileExists(ModInfoFileName))
            {
                var infoStream = modpak.ExportFileAsStream(ModInfoFileName);
                var tw         = AAPak.StreamToString(infoStream);
                tDescription.Text = tw;
            }
            else
            {
                tDescription.Text = "No description provided for this mod file.";
            }
            tDescription.SelectionLength = 0;

            if (modpak.FileExists(ModPNGImageFileName))
            {
                var picStream = modpak.ExportFileAsStream(ModPNGImageFileName);
                var img       = Image.FromStream(picStream);
                modIcon.Image = img;
            }
            else
            if (modpak.FileExists(ModJPGImageFileName))
            {
                var picStream = modpak.ExportFileAsStream(ModJPGImageFileName);
                var img       = Image.FromStream(picStream);
                modIcon.Image = img;
            }


            while (!File.Exists(GamePakFileName))
            {
                if (openGamePakDlg.ShowDialog() == DialogResult.OK)
                {
                    GamePakFileName = openGamePakDlg.FileName;
                }
                else
                {
                    return(false);
                }
            }
            Refresh();
            lInstallLocation.Text = "Loading, please wait ...";
            lInstallLocation.Refresh();
            TryLoadCustomKey(gamepak, GamePakFileName);
            if (gamepak.OpenPak(GamePakFileName, false))
            {
                lInstallLocation.Text = GamePakFileName;
            }
            else
            {
                MessageBox.Show("Failed to open ArcheAge game pak for writing\n" + GamePakFileName, "game_pak Open Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            if (RestorePakFileName == string.Empty)
            {
                RestorePakFileName = Path.GetDirectoryName(GamePakFileName).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar + ".aamod" + Path.DirectorySeparatorChar + "restore_pak";
            }

            if (File.Exists(RestorePakFileName))
            {
                if (!restorepak.OpenPak(RestorePakFileName, false))
                {
                    MessageBox.Show("Failed to open mod uninstall file for writing\n" + RestorePakFileName + "\n\nThis is most likely due to a corrupted restore file. Previously backed-up data is lost !", "restore_pak Open Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    restorepak.ClosePak();
                    if (MessageBox.Show("Do you want to create a new restore file ?\nThis step is required to be able to continue.", "Re-Create backup file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (!restorepak.NewPak(RestorePakFileName))
                        {
                            MessageBox.Show("Failed to re-create mod uninstall file\n" + RestorePakFileName, "restore_pak Create Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(RestorePakFileName));
                }
                catch
                {
                    MessageBox.Show("Failed to create mod uninstall directory for \n" + RestorePakFileName, "restore_pak Directory Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(false);
                }
                // create a new one if none exists yet
                if (!restorepak.NewPak(RestorePakFileName))
                {
                    MessageBox.Show("Failed to create mod uninstall file\n" + RestorePakFileName, "restore_pak Create Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(false);
                }
            }

            ReadNewFilesFromRestore();
            // TODO: continue work here

            return(true);
        }
Exemplo n.º 3
0
        private void ValidateInstallOptions()
        {
            // TODO: Enabled buttons depending on the state of game_pak and restore_pak compared to the aamod pak
            // Get file list from mod pak
            FilesToMod.Clear();
            foreach (var fi in modpak.files)
            {
                if (fi.name.StartsWith(ModFileFolderName))
                {
                    // Don't include own mod files
                }
                else
                {
                    // TODO: compare to gamepak to check if installed or not
                    FilesToMod.Add(fi);
                }
            }

            FilesToInstall.Clear();
            FilesAddedWithInstall.Clear();
            foreach (var fi in FilesToMod)
            {
                AAPakFileInfo gfi = gamepak.nullAAPakFileInfo;
                if (gamepak.GetFileByName(fi.name, ref gfi))
                {
                    if ((fi.size != gfi.size) || (!fi.md5.SequenceEqual(gfi.md5)))
                    {
                        FilesToInstall.Add(fi);
                    }
                }
                else
                {
                    FilesToInstall.Add(fi);
                    FilesAddedWithInstall.Add(fi);
                }
            }

            FilesToUnInstall.Clear();
            foreach (var fi in FilesToMod)
            {
                if (restorepak.FileExists(fi.name))
                {
                    FilesToUnInstall.Add(fi);
                }
            }

            if (FilesToInstall.Count > 0)
            {
                btnInstall.Enabled = true;
                string s = string.Empty;
                if (FilesToMod.Count != 1)
                {
                    s += "Mod " + FilesToMod.Count.ToString() + " file(s)";
                }
                else
                {
                    s += "Mod " + FilesToMod.Count.ToString() + " file";
                }
                if (FilesAddedWithInstall.Count > 0)
                {
                    s += ", with " + FilesAddedWithInstall.Count.ToString() + " new";
                }
                lInstallInfo.Text = s;
            }

            // Check if these same files are all present in the restore pak
            // If not, disable the uninstall option (likely not installed)
            // TODO:
            btnUninstall.Enabled = (FilesToUnInstall.Count > 0);
        }