Пример #1
0
        public static TM_FileStorage tmConfig_Load(this TM_FileStorage tmFileStorage)
        {
            if (tmFileStorage.isNull())
            {
                return(null);
            }

            var userConfigFile = tmFileStorage.tmConfig_Location();

            if (userConfigFile.fileExists())
            {
                var newConfig = userConfigFile.load <TMConfig>();    // to check that the new TMConfig is not corrupted
                if (newConfig.isNull())
                {
                    "[handleUserDataConfigActions] failed to load config file from: {0}".error(userConfigFile);
                    return(null);
                }
                TMConfig.Current = newConfig;
            }
            else
            {
                // if userConfigFile doesn't exist, create one and save it
                TMConfig.Current = new TMConfig();
                tmFileStorage.tmConfig_Save();
            }
            return(tmFileStorage);
        }
Пример #2
0
        [Admin] public static TM_FileStorage                hook_Events_TM_UserData(this TM_FileStorage tmFileStorage)
        {
            UserRole.Admin.demand();
            var tmUserData = tmFileStorage.UserData;

            tmUserData.Events.After_TM_Config_Changed.add((userData) => tmFileStorage.tmConfig_Save());

            tmUserData.Events.User_Updated.add((userData, tmUser) => tmFileStorage.saveTmUser(tmUser));
            tmUserData.Events.User_Deleted.add((userData, tmUser) => tmFileStorage.tmUser_Delete(tmUser));

            return(tmFileStorage);
        }