Esempio n. 1
0
        private void InstallMods(string path, ModManifest manifest)
        {
            var fileName = Path.GetFileName(path);
            var modName  = Path.GetFileNameWithoutExtension(path);
            var modPath  = Path.Combine(ModsTempPath, modName);


            var botPath = tbBOTDirectory.Text;
            var dbmPath = tbDBMDirectory.Text;

            Log($"Installing Mods to the provided directories, This may take a few minutes...");

            try
            {
                if (Directory.Exists(botPath))
                {
                    Log($"Installing Mods Contained In '{(manifest == null ? modName : manifest.Name)}' to BOT at  '{botPath}'");
                    AddProgress();
                    CopyFolderContents(BotTempPath, botPath);
                    AddProgress();
                }

                if (Directory.Exists(dbmPath))
                {
                    Log($"Installing Mods Contained In '{(manifest == null ? modName : manifest.Name)}' to DBM at  '{dbmPath}'");
                    AddProgress();
                    CopyFolderContents(DBMTempPath, dbmPath);
                    AddProgress();
                }
            }
            catch (Exception ex)
            {
                Log($"Could not install mods:", ex);
            }
        }
Esempio n. 2
0
        private void CopyMods(string path, string modName)
        {
            var modPath = Path.Combine(ModsTempPath, modName);

            try
            {
                AddProgress();
                ModManifest manifest = ReadManifest(modName);

                var name = manifest == null ? modName : manifest.Name;

                Log($"--------MOD INFO-----------");
                Log($"Name: {name}");

                if (manifest != null)
                {
                    Log($"Author: {manifest.Author}");
                    Log($"Version: {manifest.Version}");
                    Log($"Mod Type: {manifest.Mod.Type}");
                    Log($"Description: {manifest.Description}");
                    Log($"Repository Url: {manifest.Repository.RepositoryUrl}");
                }
                else
                {
                    Log($"No Manifest");
                }
                Log($"----------------------------");


                if (manifest != null && manifest.Mod.InstallToBot || Config.Settings.AllowModsWithoutManifests)
                {
                    Log($"Copying files for'{modName}' to BOT in '{BotTempPath}'...");
                    AddProgress();
                    CopyFolderContents(modPath, BotTempPath, manifest);
                    AddProgress();
                }

                if (manifest != null && manifest.Mod.InstallToDBM || Config.Settings.AllowModsWithoutManifests)
                {
                    AddProgress();
                    Log($"Copying files for'{modName}' to DBM '{DBMTempPath}'...");
                    CopyFolderContents(modPath, DBMTempPath, manifest);
                    AddProgress();
                }
                AddProgress();

                InstallMods(path, manifest);
            }
            catch (Exception ex)
            {
                Log($"Could not copy mods", ex);
            }
        }
Esempio n. 3
0
        private bool CopyFolderContents(string SourcePath, string DestinationPath, ModManifest manifest = null)
        {
            SourcePath      = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
            DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

            try
            {
                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                    {
                        Directory.CreateDirectory(DestinationPath);
                    }

                    foreach (string files in Directory.GetFiles(SourcePath))
                    {
                        FileInfo fileInfo = new FileInfo(files);

                        if (manifest != null)
                        {
                            if (!ShouldIgnoreFile(fileInfo.Name, manifest))
                            {
                                fileInfo.CopyTo(string.Format(@"{0}\{1}", DestinationPath, fileInfo.Name), true);
                            }
                        }
                        else
                        {
                            fileInfo.CopyTo(string.Format(@"{0}\{1}", DestinationPath, fileInfo.Name), true);
                        }
                    }

                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo directoryInfo = new DirectoryInfo(drs);
                        if (CopyFolderContents(drs, DestinationPath + directoryInfo.Name) == false)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 4
0
        private bool ShouldIgnoreFile(string path, ModManifest manifest)
        {
            var ignores = new List <string>();

            if (manifest != null)
            {
                if (path.Contains("modinfo.json"))
                {
                    return(true);
                }

                ignores.AddRange(manifest.Ignore);
            }

            if (!string.IsNullOrEmpty(Config.Settings.GlobalIgnores))
            {
                try
                {
                    var globIgnores = Config.Settings.GlobalIgnores.Split(',');

                    if (globIgnores != null && globIgnores.Length > 0)
                    {
                        ignores.AddRange(globIgnores);
                    }
                }
                catch (Exception)
                {
                }
            }

            foreach (var ignore in ignores)
            {
                string rex = "^" + Regex.Escape(ignore).Replace("\\?", ".").Replace("\\*", ".*") + "$";
                if (Regex.IsMatch(path, rex))
                {
                    return(true);
                }
            }

            return(false);
        }
 public static string ToJson(this ModManifest self) => JsonConvert.SerializeObject(self, Converter.Settings);