Beispiel #1
0
        public static bool DeleteModFromDataFolder(string?fileName)
        {
            try
            {
                if (fileName == null)
                {
                    return(false);
                }

                Shrek2Utils.EnsureAddedModsFolderExists();

                var filePath = Path.Combine(Shrek2Utils.GetAddedModsFolderPath(), fileName);

                if (File.Exists(filePath) == false)
                {
                    return(true);
                }

                File.Delete(filePath);

                return(true);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }
Beispiel #2
0
        public static bool CopyModToDataFolder(string filePath, string uuid)
        {
            try
            {
                Shrek2Utils.EnsureAddedModsFolderExists();

                File.Copy(filePath, Path.Combine(Shrek2Utils.GetAddedModsFolderPath(), $"{uuid}{Path.GetExtension(filePath)}"));

                return(true);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }
Beispiel #3
0
        public static bool ReinstallMods(string gameFolderPath, List <Shrek2ModListItem> mods)
        {
            try
            {
                if (IsModLoaderInstalled(gameFolderPath) == false)
                {
                    return(false);
                }

                if (Directory.Exists(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath)) == false)
                {
                    Directory.CreateDirectory(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath));
                }
                else
                {
                    Directory.Delete(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath), true);
                    Directory.CreateDirectory(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath));
                }

                if (mods == null || mods.Count <= 0)
                {
                    return(false);
                }

                foreach (var mod in mods)
                {
                    Directory.CreateDirectory(Path.Combine(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath), mod.UUID));
                    if (mod.ModType == Shrek2ModListItem.ModTypes.ModFile)
                    {
                        File.Copy(Path.Combine(Shrek2Utils.GetAddedModsFolderPath(), mod.FileName), Path.Combine(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath), mod.UUID, mod.FileName));
                    }
                    else if (mod.ModType == Shrek2ModListItem.ModTypes.ModZip)
                    {
                        var     zipFilePath = Path.Combine(Shrek2Utils.GetAddedModsFolderPath(), mod.FileName);
                        var     targetDir   = Path.Combine(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath), mod.UUID);
                        FastZip fastZip     = new FastZip();
                        fastZip.ExtractZip(zipFilePath, targetDir, null);

                        string dllFilePath = Path.Combine(Shrek2Utils.GetGameSystemModsFolderPath(gameFolderPath), mod.UUID, $"{mod.UUID}.dll");

                        var files = Directory.GetFiles(targetDir);

                        if (files.Length <= 0)
                        {
                            Shrek2Utils.LogError(new Exception($"Failed to install the mod '{mod.Title}' because it had no files inside of it's .zip file."));
                            return(false);
                        }

                        var zipDllName = files.FirstOrDefault(p => Path.GetExtension(p) == ".dll");

                        if (string.IsNullOrWhiteSpace(zipDllName))
                        {
                            Shrek2Utils.LogError(new Exception($"Failed to install the mod '{mod.Title}' a .dll file inside of the .zip file doesn't exist!"));
                            return(false);
                        }

                        if (File.Exists(zipDllName))
                        {
                            FileInfo fi = new FileInfo(zipDllName);

                            if (fi.Exists)
                            {
                                fi.MoveTo(dllFilePath);
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }