示例#1
0
 public List <AssetOp> GetInstallOps(ModContext context)
 {
     if (!context.Config.RootFileProvider.FileExists(context.ModPath.CombineFwdSlash(InstallLibraryFile)))
     {
         throw new Exception($"HookMod installation failed because the library file {InstallLibraryFile} could not be found.");
     }
     if (context.Config.ModLibsFileProvider.FileExists(InstallLibraryFile))
     {
         Log.LogMsg($"HookMod library file {InstallLibraryFile} already exists, it will be overwritten.");
     }
     try
     {
         var bytes = context.Config.RootFileProvider.Read(context.ModPath.CombineFwdSlash(InstallLibraryFile));
         var op    = new QueuedFileOp()
         {
             Type = QueuedFileOperationType.WriteFile, TargetPath = InstallLibraryFile, SourceData = bytes, ProviderType = QueuedFileOperationProviderType.ModLibs
         };
         return(new List <AssetOp>()
         {
             op
         });
     }
     catch (Exception ex)
     {
         Log.LogErr($"HookMod install failed to queue install mod to {InstallLibraryFile}.", ex);
         throw;
     }
 }
示例#2
0
        public List <AssetOp> GetUninstallOps(ModContext context)
        {
            List <AssetOp> ops = new List <AssetOp>();

            using (new LogTiming($"Uninstalling mod ID {ID}"))
            {
                if (Components == null || Components.Count < 1)
                {
                    Log.LogErr($"The mod with ID {ID} has no components to uninstall.");
                    throw new Exception($"The mod with ID {ID} has no components to uninstall.");
                }
                try
                {
                    foreach (var comp in Components)
                    {
                        ops.AddRange(comp.GetUninstallOps(context));
                    }
                }
                catch (Exception ex)
                {
                    Log.LogErr($"Mod ID {ID} threw an exception while uninstalling.", ex);
                    //TODO: decide if this is better than letting it be screwed up or not.
                    //throw new Exception($"Mod ID {ID} failed to uninstall.", ex);
                }
            }
            ops.Add(new ModStatusOp(this, ModStatusType.NotInstalled));
            return(ops);
        }
 public override List <AssetOp> GetUninstallOps(ModContext context)
 {
     if (UninstallAction == null)
     {
         throw new InvalidOperationException("HookMod is being uninstalled, but has no uninstall action!");
     }
     return(UninstallAction.GetUninstallOps(context));
 }
 public override List <AssetOp> GetInstallOps(ModContext context)
 {
     Log.LogMsg($"Installing HookMod component");
     if (InstallAction == null)
     {
         throw new InvalidOperationException("HookMod is being installed, but has no install action!");
     }
     return(InstallAction.GetInstallOps(context));
 }
示例#5
0
        public List <AssetOp> GetInstallModOps(ModDefinition modDef)
        {
            List <AssetOp> ops = new List <AssetOp>();
            ModContext     mc  = new ModContext(_config.ModsSourcePath.CombineFwdSlash(modDef.ID), _config, _getEngine);

            if (modDef.Category.IsExclusiveMod())
            {
                var otherSabers = Mods.Where(x => x.Category == modDef.Category && x.ID != modDef.ID && x.Status == ModStatusType.Installed);
                foreach (var otherSaber in otherSabers)
                {
                    ops.AddRange(otherSaber.GetUninstallOps(mc));
                }
            }

            ops.AddRange(modDef.GetInstallOps(mc));
            return(ops);
        }
示例#6
0
        public override List <AssetOp> GetInstallOps(ModContext context)
        {
            Log.LogMsg($"Installing FileCopy component");
            if (string.IsNullOrEmpty(SourceFileName))
            {
                throw new InvalidOperationException("FileCopy is being installed, but has no filename!");
            }
            if (string.IsNullOrEmpty(TargetRootedPathAndFileName))
            {
                throw new InvalidOperationException("FileCopy is being installed, but has no root filesystem target path!");
            }

            if (!context.Config.RootFileProvider.FileExists(context.ModPath.CombineFwdSlash(SourceFileName)))
            {
                throw new Exception($"FileCopy installation failed because the file {SourceFileName} could not be found.");
            }
            if (System.IO.File.Exists(TargetRootedPathAndFileName))
            {
                Log.LogMsg($"FileCopy target file {TargetRootedPathAndFileName} already exists, it will be overwritten.");
            }
            try
            {
                var bytes = context.Config.RootFileProvider.Read(context.ModPath.CombineFwdSlash(SourceFileName));
                var op    = new QueuedFileOp()
                {
                    Type = QueuedFileOperationType.WriteFile, TargetPath = TargetRootedPathAndFileName, SourceData = bytes, ProviderType = QueuedFileOperationProviderType.FileSystemRoot
                };
                return(new List <AssetOp>()
                {
                    op
                });
            }
            catch (Exception ex)
            {
                Log.LogErr($"FileCopy install failed to queue install mod to {TargetRootedPathAndFileName}.", ex);
                throw;
            }
        }
示例#7
0
 public List <AssetOp> GetUninstallOps(ModContext context)
 {
     if (!context.Config.ModLibsFileProvider.FileExists(RemoveLibraryFile))
     {
         Log.LogErr($"Tried uninstalling HookMod library {RemoveLibraryFile} but it did not exist.");
         return(new List <AssetOp>());
     }
     try
     {
         var op = new QueuedFileOp()
         {
             ProviderType = QueuedFileOperationProviderType.ModLibs, TargetPath = RemoveLibraryFile, Type = QueuedFileOperationType.DeleteFile
         };
         return(new List <AssetOp>()
         {
             op
         });
     }
     catch (Exception ex)
     {
         Log.LogErr($"Uninstall HookMod failed to queue delete file {RemoveLibraryFile}!", ex);
         throw;
     }
 }
示例#8
0
        public override List <AssetOp> GetUninstallOps(ModContext context)
        {
            if (string.IsNullOrWhiteSpace(TargetRootedPathAndFileName))
            {
                return(new List <AssetOp>());
            }

            try
            {
                var op = new QueuedFileOp()
                {
                    ProviderType = QueuedFileOperationProviderType.FileSystemRoot, TargetPath = TargetRootedPathAndFileName, Type = QueuedFileOperationType.DeleteFile
                };
                return(new List <AssetOp>()
                {
                    op
                });
            }
            catch (Exception ex)
            {
                Log.LogErr($"Uninstall HookMod failed to queue delete file {TargetRootedPathAndFileName}!", ex);
                throw;
            }
        }
示例#9
0
        public List <AssetOp> GetInstallOps(ModContext context)
        {
            List <AssetOp> ops = new List <AssetOp>();

            using (new LogTiming($"Installing mod ID {ID}"))
            {
                if (Components == null || Components.Count < 1)
                {
                    Log.LogErr($"The mod with ID {ID} has no components to install.");
                    throw new Exception($"The mod with ID {ID} has no components to install.");
                }
                try
                {
                    foreach (var comp in Components)
                    {
                        ops.AddRange(comp.GetInstallOps(context));
                    }
                }
                catch (Exception ex)
                {
                    Log.LogErr($"Mod ID {ID} threw an exception while installing.", ex);
                    throw new Exception($"Mod ID {ID} failed to install.", ex);
                }
            }
            List <AssetOp> checkList = new List <AssetOp>();
            bool           failures  = false;
            bool           successes = false;

            checkList.AddRange(ops);
            EventHandler <AssetOp> ev = null;

            ev = new EventHandler <AssetOp>((e, a) =>
            {
                bool done = false;
                if (a.Status == OpStatus.Complete)
                {
                    successes = true;
                    done      = true;
                }
                if (a.Status == OpStatus.Failed)
                {
                    failures = true;
                    done     = true;
                }
                if (done)
                {
                    a.OpFinished -= ev;
                    checkList.Remove(a);
                }

                if (checkList.Count < 1)
                {
                    if (!failures)
                    {
                        context.GetEngine().OpManager.QueueOp(new ModStatusOp(this, ModStatusType.Installed));
                    }
                    else
                    {
                        if (successes)
                        {
                            Log.LogErr("Mod install had failures, but some ops succeeded.  Trying to uninstall whatever components will uninstall.");
                        }
                        try
                        {
                            context.GetEngine().ModManager.GetUninstallModOps(this).ForEach(x => context.GetEngine().OpManager.QueueOp(x));
                        } catch (Exception ex)
                        {
                            Log.LogErr("Exception trying to uninstall failed mod components.  Not entirely unexpected since it failed to install to begin with.");
                        }

                        context.GetEngine().OpManager.QueueOp(new ModStatusOp(this, ModStatusType.NotInstalled));
                    }
                }
            });
            checkList.ForEach(x => x.OpFinished += ev);

            return(ops);
        }
示例#10
0
        public List <AssetOp> GetUninstallModOps(ModDefinition modDef)
        {
            ModContext mc = new ModContext(_config.ModsSourcePath.CombineFwdSlash(modDef.ID), _config, _getEngine);

            return(modDef.GetUninstallOps(mc));
        }
示例#11
0
 public abstract List <AssetOp> GetUninstallOps(ModContext context);