Ejemplo n.º 1
0
        private IReadOnlyDictionary <string, ModelFileInfo> getFiles(string directory, string[] ignores)
        {
            var checkedFiles = FileChecker.GenerateHashFiles(directory, writeFolderNameToServerLog);
            var files        = checkedFiles
                               .Where(x => !FileNameContainsIgnored(new FileInfo(x.FileName).Name, ignores));

            var res = files.ToDictionary(f => f.FileName.ToLower());

            Loger.Log($"Hashed {res.Count} files from ModsDirectory={directory}");
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send hash files of loaded mods to server and update it if hash different
        /// </summary>
        public static void StartGenerateHashFiles(string modsFileName, string steamFileName)
        {
            var modsListFolder  = File.ReadAllLines(modsFileName);
            var steamListFolder = File.ReadAllLines(steamFileName);

            Loger.Log("Start Hash:" + modsFileName);
            Loger.Log("Start Hash:" + steamFileName);
            // может быть есть лучше вариант, как указать папку модов со steam ???
            SteamFolder = GenFilePaths.ModsFolderPath.Replace("common\\RimWorld\\Mods", "workshop\\content\\294100");
            Loger.Log("GenFilePaths.ModsConfigFilePath = " + GenFilePaths.ModsConfigFilePath);
            if (SteamFolder.Equals(GenFilePaths.ModsFolderPath) || !Directory.Exists(SteamFolder))
            {
                var steamFolder = Path.Combine(SessionClientController.ConfigPath, "workshop");
                Log.Message($"Directory {SteamFolder} not found, using {steamFolder}");
                if (!Directory.Exists(steamFolder))
                {
                    Log.Message($"Create {steamFolder}");
                    Log.Message("Таян наверное расстроится, скорее всего используется пиратская версия игры");
                    Directory.CreateDirectory(steamFolder);
                }

                SteamFolder = steamFolder;
            }

            Loger.Log("SteamFolder=" + SteamFolder);

            CheckHashModsThread = new Thread(() =>
            {
                lock (CheckHashModsThreadSunc)
                {
                    try
                    {
                        Loger.Log($"GenerateHashFiles {GenFilePaths.ModsFolderPath}");
                        ClientHashChecker.ModsFiles = FileChecker.GenerateHashFiles(GenFilePaths.ModsFolderPath, modsListFolder);
                        Loger.Log($"GenerateHashFiles {SteamFolder}");
                        ClientHashChecker.SteamFiles = FileChecker.GenerateHashFiles(SteamFolder, steamListFolder);
                    }
                    catch (Exception exc)
                    {
                        Loger.Log($"GenerateHashFiles Exception {exc.ToString()}");
                    }
                    CheckHashModsThreadRun = false;
                }
            });
            CheckHashModsThreadRun           = true;
            CheckHashModsThread.IsBackground = true;
            CheckHashModsThread.Start();
        }
Ejemplo n.º 3
0
 public void CalculateHash()
 {
     Loger.Log($"{FolderType.ToString()} {Folder}");
     FilesHash = FileChecker.GenerateHashFiles(Folder, OnChangeFolderAction);
 }
Ejemplo n.º 4
0
        private void createFilesDictionary()
        {
            if (!ServerSettings.IsModsWhitelisted)
            {
                return;
            }

            // 1. Создаем словарь со всеми файлами
            Loger.Log($"Calc hash {ServerSettings.ModsDirectory}");
            var modFiles = FileChecker.GenerateHashFiles(ServerSettings.ModsDirectory, Directory.GetDirectories(ServerSettings.ModsDirectory));

            Loger.Log($"Calc hash {ServerSettings.SteamWorkShopModsDir}");
            ///!!!!!!!!!!!!!!!! STEAM FOLDER CHECK SWITCH HERE  !!!!!!!!!!!!!!!
            // 1. Если будем использовать steamworkshop диреторию, эти две строчки ниже закомментировать
            // 2. remove JsobIgnrore atribbute in ServerSettings
            ServerSettings.SteamWorkShopModsDir = Environment.CurrentDirectory;
            ///!!!!!!!!!!!!!!!! STEAM FOLDER CHECK SWITCH HERE  !!!!!!!!!!!!!!!
            var steamFiles = FileChecker.GenerateHashFiles(ServerSettings.SteamWorkShopModsDir, new string[0]);

            ModFilesDict   = modFiles.ToDictionary(f => f.FileName);
            SteamFilesDict = steamFiles.ToDictionary(f => f.FileName);

            // 2. Создаем файлы со списком разрешенных папок, которые отправим клиенту
            var modsFolders = new ModelFileInfo() // 0
            {
                FileName = "ApprovedMods.txt",
                Hash     = FileChecker.CreateListFolder(ServerSettings.ModsDirectory)
            };
            var steamFolders = new ModelFileInfo() // 1
            {
                FileName = "ApprovedSteamWorkShop.txt",
                Hash     = FileChecker.CreateListFolder(ServerSettings.SteamWorkShopModsDir)
            };
            var modsConfigFileName = Path.Combine(ServerSettings.WorkingDirectory, "ModsConfig.xml");
            var modsConfig         = new ModelFileInfo() // 2
            {
                FileName = "ModsConfig.xml",
                Hash     = Encoding.UTF8.GetBytes(File.ReadAllText(modsConfigFileName))
            };

            // index: 0 - list Folders in Mods dir, 1 -list Folders in Steam dir , 2 - ModsConfig.xml
            ServerSettings.AppovedFolderAndConfig = new ModelModsFiles()
            {
                Files = new List <ModelFileInfo>()
                {
                    modsFolders,
                    steamFolders,
                    modsConfig,
                }
            };

            ServerSettings.ModsDirConfig = new ModelModsFiles()
            {
                IsSteam = false,
                Files   = new List <ModelFileInfo>()
                {
                    modsFolders
                },
                FoldersTree = FoldersTree.GenerateTree(ServerSettings.ModsDirectory),
            };

            ServerSettings.SteamDirConfig = new ModelModsFiles()
            {
                IsSteam = true,
                Files   = new List <ModelFileInfo>()
                {
                    steamFolders
                },
                FoldersTree = FoldersTree.GenerateTree(ServerSettings.SteamWorkShopModsDir),
            };
        }