示例#1
0
        public List <InstalledASIMod> GetInstalledASIs()
        {
            List <InstalledASIMod> installedASIs = new List <InstalledASIMod>();

            try
            {
                string asiDirectory = MEDirectories.ASIPath(this);
                if (asiDirectory != null && Directory.Exists(TargetPath))
                {
                    if (!Directory.Exists(asiDirectory))
                    {
                        Directory.CreateDirectory(asiDirectory); //Create it, but we don't need it
                        return(installedASIs);                   //It won't have anything in it if we are creating it
                    }

                    var asiFiles = Directory.GetFiles(asiDirectory, @"*.asi");
                    foreach (var asiFile in asiFiles)
                    {
                        var hash = Utilities.CalculateMD5(asiFile);
                        var matchingManifestASI = ASIManager.GetASIVersionByHash(hash, Game);
                        if (matchingManifestASI != null)
                        {
                            installedASIs.Add(new KnownInstalledASIMod(asiFile, hash, Game, matchingManifestASI));
                        }
                        else
                        {
                            installedASIs.Add(new UnknownInstalledASIMod(asiFile, hash, Game));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(@"Error fetching list of installed ASIs: " + e.Message);
            }

            return(installedASIs);
        }
示例#2
0
        private static Action HandleCommandLineJumplistCall(string[] args, out int exitCode)
        {
            exitCode = 0;
            if (args.Length < 2)
            {
                return(() => { }); //do nothing delgate. Will do nothing when main UI loads
            }

            string arg = args[1];

            if (arg == "JUMPLIST_PACKAGE_EDITOR")
            {
                return(() =>
                {
                    PackageEditorWPF editor = new PackageEditorWPF();
                    editor.Show();
                    editor.Activate();
                });
            }

            if (arg == "JUMPLIST_SEQUENCE_EDITOR")
            {
                return(() =>
                {
                    var editor = new SequenceEditorWPF();
                    editor.Show();
                    editor.Activate();
                });
            }

            if (arg == "JUMPLIST_PATHFINDING_EDITOR")
            {
                return(() =>
                {
                    PathfindingEditorWPF editor = new PathfindingEditorWPF();
                    editor.Show();
                    editor.Activate();
                });
            }

            if (arg == "JUMPLIST_SOUNDPLORER")
            {
                return(() =>
                {
                    SoundplorerWPF soundplorerWpf = new SoundplorerWPF();
                    soundplorerWpf.Show();
                    soundplorerWpf.Activate();
                });
            }

            //Do not remove - used by Mass Effect Mod Manager to boot the tool
            if (arg == "JUMPLIST_ASIMANAGER")
            {
                return(() =>
                {
                    ASIManager asiManager = new ASIManager();
                    asiManager.Show();
                    asiManager.Activate();
                });
            }

            //Do not remove - used by Mass Effect Mod Manager to boot the tool
            if (arg == "JUMPLIST_MOUNTEDITOR")
            {
                return(() =>
                {
                    MountEditorWPF mountEditorWpf = new MountEditorWPF();
                    mountEditorWpf.Show();
                    mountEditorWpf.Activate();
                });
            }

            //Do not remove - used by Mass Effect Mod Manager to boot the tool
            if (arg == "JUMPLIST_PACKAGEDUMPER")
            {
                return(() =>
                {
                    PackageDumper.PackageDumper packageDumper = new PackageDumper.PackageDumper();
                    packageDumper.Show();
                    packageDumper.Activate();
                });
            }

            //Do not remove - used by Mass Effect Mod Manager to boot the tool
            if (arg == "JUMPLIST_DLCUNPACKER")
            {
                return(() =>
                {
                    DLCUnpacker.DLCUnpackerUI dlcUnpacker = new DLCUnpacker.DLCUnpackerUI();
                    dlcUnpacker.Show();
                    dlcUnpacker.Activate();
                });
            }

            if (arg == "JUMPLIST_DIALOGUEEDITOR")
            {
                return(() =>
                {
                    DialogueEditorWPF editor = new DialogueEditorWPF();
                    editor.Show();
                    editor.Activate();
                });
            }

            if (arg == "JUMPLIST_MESHPLORER")
            {
                return(() =>
                {
                    MeshplorerWPF meshplorerWpf = new MeshplorerWPF();
                    meshplorerWpf.Show();
                    meshplorerWpf.Activate();
                });
            }


            string ending = Path.GetExtension(args[1]).ToLower();

            switch (ending)
            {
            case ".pcc":
            case ".sfm":
            case ".upk":
            case ".u":
            case ".udk":
                return(() =>
                {
                    PackageEditorWPF editor = new PackageEditorWPF();
                    editor.Show();
                    editor.LoadFile(args[1]);
                    editor.RestoreAndBringToFront();
                });
                //return 2; //Do not signal bring main forward
            }
            exitCode = 0; //is this even used?
            return(null);
        }
        public void TestASIManager()
        {
            GlobalTest.Init();
            Random random = new Random();

            Console.WriteLine(@"Loading ASI Manager Manifest");
            ASIManager.LoadManifest();

            var games = new[] { Mod.MEGame.ME1, Mod.MEGame.ME2, Mod.MEGame.ME3 };

            foreach (var game in games)
            {
                var        root   = GlobalTest.GetTestGameFoldersDirectory(game);
                var        normal = Path.Combine(root, "normal");
                GameTarget gt     = new GameTarget(game, normal, true, false);

                var asiDir = MEDirectories.ASIPath(gt);
                if (Directory.Exists(asiDir))
                {
                    // Clean slate
                    Utilities.DeleteFilesAndFoldersRecursively(asiDir);
                }

                var asisForGame = ASIManager.GetASIModsByGame(game);

                // 1: Test Installs of upgrades of versions
                foreach (var asi in asisForGame)
                {
                    // Install every version of an ASI and then ensure only one ASI of that type exists in the directory.
                    foreach (var v in asi.Versions)
                    {
                        var sourceBools = new bool?[] { true, false, null }; //online, local, let app decide
                        foreach (var sourceBool in sourceBools)
                        {
                            // INSTALL FROM SOURCE
                            Console.WriteLine($@"Install source variable: {sourceBool}");
                            Assert.IsTrue(ASIManager.InstallASIToTarget(v, gt, sourceBool),
                                          $"Installation of ASI failed: {v.Name}");
                            Assert.AreEqual(1, Directory.GetFiles(asiDir).Length,
                                            "The count of files in the ASI directory is not 1 after install of an ASI!");

                            // Check is installed
                            var installedASIs = gt.GetInstalledASIs().OfType <KnownInstalledASIMod>().ToList();
                            Assert.AreEqual(1, installedASIs.Count,
                                            "The amount of installed ASIs as fetched by GameTarget GetInstalledASIs() is not equal to 1!");

                            // Check it maps to the correct one.
                            var instASI = installedASIs.First();
                            Assert.AreEqual(v, instASI.AssociatedManifestItem, "The parsed installed ASI does not match the one we fed to ASIManager.InstallASIToTarget()!");

                            // Rename it to something random so the next version has to find it by the hash and not the filename.
                            var newPath = Path.Combine(asiDir, Guid.NewGuid() + ".asi");
                            File.Move(instASI.InstalledPath, newPath, false);

                            // Ensure it still can be found.
                            installedASIs = gt.GetInstalledASIs().OfType <KnownInstalledASIMod>().ToList();
                            Assert.AreEqual(1, installedASIs.Count, "The amount of installed ASIs as fetched by GameTarget GetInstalledASIs() is not equal to 1 after renaming the file!");

                            // Make multiple clones, to ensure all old ones get deleted on upgrades.
                            for (int i = 0; i < 5; i++)
                            {
                                var clonePath = Path.Combine(asiDir, instASI.AssociatedManifestItem.InstalledPrefix + i + ".asi");
                                File.Copy(newPath, clonePath, true);
                            }

                            installedASIs = gt.GetInstalledASIs().OfType <KnownInstalledASIMod>().ToList();
                            Assert.AreEqual(6, installedASIs.Count, "The amount of installed ASIs as fetched by GameTarget GetInstalledASIs() is not equal to 6 after cloning the file 5 times!");
                        }
                    }

                    var finalASIsPreRandomization = gt.GetInstalledASIs();
                    int randomCount = 0;
                    foreach (var iam in finalASIsPreRandomization)
                    {
                        // Test randomly editing it.
                        byte[] randomData = new byte[256];
                        random.NextBytes(randomData);
                        File.WriteAllBytes(iam.InstalledPath, randomData);
                        randomCount++;

                        var unknownInstalledASIs = gt.GetInstalledASIs().OfType <UnknownInstalledASIMod>().ToList();
                        Assert.AreEqual(randomCount, unknownInstalledASIs.Count, "Writing random bytes to installed ASI made amount of installed ASIs not correct!");
                    }

                    foreach (var v in finalASIsPreRandomization)
                    {
                        // Test uninstall and remove
                        Assert.IsTrue(v.Uninstall(), $"ASI failed to uninstall: {v.InstalledPath}");
                    }
                    Assert.AreEqual(0, Directory.GetFiles(asiDir).Length, "Leftover files remain after uninstalling all ASIs from target");
                }
            }
        }