Example #1
0
        public static void LoadConfiguation()
        {
            StorageFile storageFile;

            _ = ApplicationStorage.Configuration.CreateFile(TrustedInstaller, "Server.ini", out storageFile);
            ConfigurationData = INILikeData.LoadFromStream(storageFile.OpenFileWR(TrustedInstaller));
        }
Example #2
0
 static void LoadApplicationStorage()
 {
     _BasePath = new FileInfo(Assembly.GetAssembly(typeof(ApplicationStorage)).Location).DirectoryName;
     {
         SystemRoot            = new StorageFolder();
         SystemRoot.parent     = null;
         SystemRoot.isvirtual  = true;
         SystemRoot.isreadonly = true;
         SystemRoot.realPath   = "{Root}";
     }
     {
         _Webroot        = new StorageFolder();
         _Webroot.Parent = SystemRoot;
         _Webroot.isroot = true;
     }
     {
         _ModuleRoot        = new StorageFolder();
         _ModuleRoot.Parent = SystemRoot;
         _ModuleRoot.isroot = true;
     }
     {
         Configuration          = new StorageFolder();
         Configuration.Parent   = SystemRoot;
         Configuration.isroot   = true;
         Configuration.realPath = Path.Combine(_BasePath, "Configurations");
         Configuration.SetDeletePermissionID(PermissionID.Config_Delete, PermissionID.ConfigAll);
         Configuration.SetBaseWritePermission(PermissionID.ModifyConfig, PermissionID.ConfigAll);
         Configuration.SetBaseReadPermission(PermissionID.ReadConfig, PermissionID.ConfigAll);
         if (!Directory.Exists(Configuration.realPath))
         {
             Directory.CreateDirectory(Configuration.realPath);
         }
     }
     {
         Logs          = new StorageFolder();
         Logs.Parent   = SystemRoot;
         Logs.isroot   = true;
         Logs.realPath = Path.Combine(_BasePath, "Logs");
         Logs.SetDeletePermissionID(PermissionID.ClearLogFolder, PermissionID.Log_All);
         Logs.SetBaseWritePermission(PermissionID.Log_NewFile, PermissionID.Log_All);
         Logs.SetBaseReadPermission(PermissionID.Log_EnumerateFile, PermissionID.Log_All);
         if (!Directory.Exists(Logs.realPath))
         {
             Directory.CreateDirectory(Logs.realPath);
         }
     }
     try
     {
         StorageFile Routes;
         _ = Configuration.CreateFile(TrustedInstaller, "RoutedLocations.ini", out Routes);
         RouteLocationMap = INILikeData.LoadFromWR(new FileWR(Routes.ToFileInfo(TrustedInstaller)));
         foreach (var item in RouteLocationMap)
         {
             Map.Add(item.Key.Replace('\\', '/'), item.Value);
         }
     }
     catch (Exception)
     {
     }
 }
Example #3
0
        internal ApplicationConfiguration(string ModuleName)
        {
            var  moduleConfigFolder = ApplicationStorage.Configuration.CreateFolder(GlobalConfiguration.TrustedInstaller, "Modules", true);
            bool b = moduleConfigFolder.CreateFile(GlobalConfiguration.TrustedInstaller, ModuleName + ".ini", out sf);

            FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(sf.Parent.ItemPath, sf.Name);

            fileSystemWatcher.Changed += (_a, _b) =>
            {
                RawData = INILikeData.LoadFromWR(new FileWR(sf.ToFileInfo(GlobalConfiguration.TrustedInstaller)));
            };
            //var fs = moduleConfigFolder.GetFiles(GlobalConfiguration.TrustedInstaller);
            //foreach (var item in fs)
            //{
            //    if (item.Name == ModuleName + ".ini")
            //    {
            //        RawData = INILikeData.LoadFromWR(new FileWR(item.ToFileInfo(GlobalConfiguration.TrustedInstaller)));
            //        return;
            //    }
            //}
            if (b == false)
            {
                RawData = INILikeData.LoadFromWR(new FileWR(sf.ToFileInfo(GlobalConfiguration.TrustedInstaller)));
            }
            else
            {
                RawData = INILikeData.CreateToWR(new FileWR(sf.ToFileInfo(GlobalConfiguration.TrustedInstaller)));
            }
        }
Example #4
0
        /// <summary>
        /// Init language dictionary with given culture information string (e.g.: en-US).
        /// </summary>
        /// <param name="CultureInfo"></param>
        public static void Initialize(string CultureInfo)
        {
            Assembly      assembly    = typeof(Language).Assembly;
            DirectoryInfo location    = new DirectoryInfo(Path.Combine(new FileInfo(assembly.Location).DirectoryName, "Locales", CultureInfo.ToUpper()));
            DirectoryInfo location_en = new DirectoryInfo(Path.Combine(new FileInfo(assembly.Location).DirectoryName, "Locales", "EN-US"));

            if (!location.Exists)
            {
                location = new DirectoryInfo(Path.Combine(new FileInfo(assembly.Location).DirectoryName, "Locales", "EN-US"));
            }
            if (!location.Exists)
            {
                Trace.WriteLine("Cannot find applicable language files.");
                return;
            }
            LanguageStrings.Clear();
            //Load english first.
            foreach (var item in location_en.EnumerateFiles())
            {
                INILikeData keyValuePairs = INILikeData.LoadFromWR(new FileWR(item));
                string      Namespace     = keyValuePairs.FindValue("Namespace");
                foreach (var ID in keyValuePairs)
                {
                    if (ID.Key != "Namespace")
                    {
                        var Key = $"{Namespace}.{ID.Key}";
                        if (LanguageStrings.ContainsKey(Key))
                        {
                            LanguageStrings[Key] = ID.Value;
                        }
                        else
                        {
                            LanguageStrings.Add(Key, ID.Value);
                        }
                    }
                }
                keyValuePairs.Dispose();
            }

            //Then load target language.
            if (location.FullName != location_en.FullName)
            {
                foreach (var item in location.EnumerateFiles())
                {
                    INILikeData keyValuePairs = INILikeData.LoadFromWR(new FileWR(item));
                    string      Namespace     = keyValuePairs.FindValue("Namespace");
                    foreach (var ID in keyValuePairs)
                    {
                        if (ID.Key != "Namespace")
                        {
                            var Key = $"{Namespace}.{ID.Key}";
                            if (LanguageStrings.ContainsKey(Key))
                            {
                                LanguageStrings[Key] = ID.Value;
                            }
                            else
                            {
                                LanguageStrings.Add(Key, ID.Value);
                            }
                        }
                    }
                    keyValuePairs.Dispose();
                }
            }
        }
Example #5
0
 public void Reload()
 {
     RawData = INILikeData.LoadFromWR(new FileWR(sf.ToFileInfo(GlobalConfiguration.TrustedInstaller)));
 }