예제 #1
0
        private Dictionary <string, List <(string, uint)> > GetMods(ServerModsManifest modsManifest)
        {
            List <string> WhiteList = Mods.WhiteListMods;

            List <string> mods = new List <string>();

            foreach (string mod in modsManifest.LoadOrder)
            {
                string modName = Path.GetFileNameWithoutExtension(mod);
                if (!mods.Contains(modName) && !WhiteList.Contains(modName))
                {
                    mods.Add(modName);
                }
            }

            Dictionary <string, List <(string, uint)> > files = new Dictionary <string, List <(string, uint)> >();

            foreach (string mod in mods)
            {
                files.Add(mod,
                          modsManifest.Mods.FindAll(m => Path.GetFileNameWithoutExtension(m.FileName) == mod).Select(s => (s.FileName, (uint)s.CRC32)).ToList());
            }

            return(files);
        }
예제 #2
0
        private static async Task <bool> SetMods(string adress)
        {
            string path    = DefaultPaths.PathToLocalSkyrim + "Plugins.txt";
            string content = "";

            try
            {
                await Mods.DisableAll();

                ServerModsManifest mods = Mods.CheckCore(await GetManifest(adress));
                Dictionary <string, List <(string, uint)> > needMods = mods.GetMods();

                foreach (KeyValuePair <string, List <(string, uint)> > mod in needMods)
                {
                    if (!Mods.ExistMod(mod.Key) || !Mods.CheckMod(mod.Key, mod.Value))
                    {
                        string tmpPath = Mods.GetTmpPath();
                        string desPath = tmpPath + "\\Data\\";

                        IO.CreateDirectory(desPath);
                        string mainFile = null;
                        foreach (var file in mod.Value)
                        {
                            ServerList.ShowProgressBar = true;
                            await DownloadMod(desPath + file.Item1, adress, file.Item1);

                            ServerList.ShowProgressBar = false;
                            if (mods.LoadOrder.Contains(file.Item1))
                            {
                                mainFile = file.Item1;
                            }
                        }
                        await Mods.AddMod(mod.Key, "", tmpPath, true, mainFile);
                    }
                    await Mods.EnableMod(mod.Key);
                }

                foreach (var item in mods.LoadOrder)
                {
                    content += $"*{item}\n";
                }
            }
            catch (HttpRequestException)
            {
                if (NetworkSettings.CompatibilityMode)
                {
                    NotifyController.Show(Res.CompatibilityModeOn);
                    if (Mods.ExistMod("Farm"))
                    {
                        await Mods.OldModeEnable();
                    }
                    await Task.Delay(3000);

                    content = @"*FarmSystem.esp";
                }
                else
                {
                    NotifyController.Show(Res.CompatibilityModeOff);
                    return(false);
                }
            }
            catch (WebException)
            {
                if (NetworkSettings.CompatibilityMode)
                {
                    NotifyController.Show(Res.CompatibilityModeOn);
                    if (Mods.ExistMod("Farm"))
                    {
                        await Mods.OldModeEnable();
                    }
                    await Task.Delay(3000);

                    content = @"*FarmSystem.esp";
                }
                else
                {
                    NotifyController.Show(Res.CompatibilityModeOff);
                    return(false);
                }
            }
            catch (FileNotFoundException)
            {
                NotifyController.Show(Res.DownloadModError);
                return(false);
            }
            catch (Exception e)
            {
                Logger.Error("EnablerMods", e);
                NotifyController.Show(e);
                return(false);
            }

            try
            {
                if (!Directory.Exists(DefaultPaths.PathToLocalSkyrim))
                {
                    Directory.CreateDirectory(DefaultPaths.PathToLocalSkyrim);
                }
                if (File.Exists(path) && File.GetAttributes(path) != FileAttributes.Normal)
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
                File.WriteAllText(path, content);
            }
            catch (UnauthorizedAccessException)
            {
                FileAttributes attr = new FileInfo(path).Attributes;
                Logger.Error("Write_Plugin_UAException", new UnauthorizedAccessException($"Unable to access file. Attributes: {attr}"));
            }
            catch (Exception e)
            {
                Logger.Error("Write_Plugin_txt", e);
            }
            return(true);
        }
예제 #3
0
        private async Task <bool> SetMods(string adress)
        {
            string path    = Settings.PathToLocalSkyrim + "Plugins.txt";
            string content = "";

#if (DEBUG)
            bool d = true;
#else
            bool d = false;
#endif

            if (d || (NetworkSettings.EnableModLoader && ExperimentalFunctions.HasExperimentalFunctions()))
            {
                try
                {
                    Mods.DisableAll();
                    ServerModsManifest mods = Mods.CheckCore(await GetManifest(adress));
                    Dictionary <string, List <(string, uint)> > needMods = GetMods(mods);

                    foreach (KeyValuePair <string, List <(string, uint)> > mod in needMods)
                    {
                        if (!Mods.ExistMod(mod.Key) || !Mods.CheckMod(mod.Key, mod.Value))
                        {
                            string tmpPath = Mods.GetTmpPath();
                            string desPath = tmpPath + "\\Data\\";

                            IO.CreateDirectory(desPath);
                            string mainFile = null;
                            foreach (var file in mod.Value)
                            {
                                await DownloadMod(desPath + file.Item1, adress, file.Item1);

                                if (mods.LoadOrder.Contains(file.Item1))
                                {
                                    mainFile = file.Item1;
                                }
                            }
                            Mods.AddMod(mod.Key, "", tmpPath, true, mainFile);
                        }
                        Mods.EnableMod(Path.GetFileNameWithoutExtension(mod.Key));
                    }

                    foreach (var item in mods.LoadOrder)
                    {
                        content += $"*{item}\n";
                    }
                }
                catch (WebException)
                {
                    if (NetworkSettings.CompatibilityMode)
                    {
                        NotifyController.Show(PopupNotify.Normal, Res.Attempt, "Вероятно целевой сервер устер, используется режим совместимости");
                        if (Mods.ExistMod("Farm"))
                        {
                            Mods.OldModeEnable();
                        }
                        await Task.Delay(3000);

                        content = @"*FarmSystem.esp";
                    }
                    else
                    {
                        NotifyController.Show(PopupNotify.Error, Res.Attempt, "Возможно целевой сервер устарел, так как не ответил на запрос");
                        return(false);
                    }
                }
                catch (FileNotFoundException)
                {
                    NotifyController.Show(PopupNotify.Error, Res.Error, "Один или несколько модов не удалось загрузить с сервера");
                    return(false);
                }
                catch (Exception e)
                {
                    Logger.Error("EnablerMods", e);
                    NotifyController.Show(e);
                    return(false);
                }
            }
            else
            {
                content = @"*FarmSystem.esp";
            }

            try
            {
                if (!Directory.Exists(Settings.PathToLocalSkyrim))
                {
                    Directory.CreateDirectory(Settings.PathToLocalSkyrim);
                }
                if (File.Exists(path) && File.GetAttributes(path) != FileAttributes.Normal)
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
                File.WriteAllText(path, content);
            }
            catch (UnauthorizedAccessException)
            {
                FileAttributes attr = new FileInfo(path).Attributes;
                Logger.Error("Write_Plugin_UAException", new UnauthorizedAccessException($"UnAuthorizedAccessException: Unable to access file. Attributes: {attr}"));
            }
            catch (Exception e)
            {
                Logger.Error("Write_Plugin_txt", e);
            }
            return(true);
        }