private void Initialize() { //Bitmap32.Loader = new SkiaBitmap32Loader(); string configFile = FileSystem.Combine(FileSystem.ProgramDirectory, "../../../config", "IseSkin.ini"); config = IniReader.FromFile(configFile); renderer = new Glfw3Renderer(); if (!renderer.IsAvailable) { throw new Exception("renderer is not available!"); } IRenderDevice[] devs = renderer.GetDevices(); if (devs.Length < 1) { throw new Exception("no devices found"); } renderer.Closed += WindowClosed; renderer.MouseButtonChanged += MBChanged; renderer.FrameBufferChanged += FBChanged; renderer.Initialize(devs[0], RendererMode.Window, RendererFlags.WaitRetrace, 1024, 768, "OpenGL Test"); iseSkin = new IseSkin(renderer); UpdateConfig(); initDone = true; }
static ProgramConfig() { var log = new Logger("Cardinal"); log.LogInfo("Loading configuration..."); var configFileName = Path.ChangeExtension(typeof(ProgramConfig).Assembly.GetAssemblyFilePath(), ".ini"); var config = IniReader.FromFile(configFileName); var service = config.ReadStructFields <ServiceSettings>("Service"); var i = AssemblyVersionInfo.Program; service.Description ??= i.Description; service.Title ??= i.Title; service.Name ??= i.Product; service.StartMode = service.StartMode == 0 ? ServiceStartMode.Automatic : service.StartMode; Service = service; var slaves = new List <SlaveHandler>(); foreach (var slaveName in config.ReadSection("slaves")) { var slaveSection = $"slave:{slaveName}"; if (config.HasSection(slaveSection)) { var slaveConfig = config.ReadStructFields <SlaveConfig>(slaveSection); slaveConfig.Name = slaveName; slaves.Add(new SlaveHandler(slaveConfig)); } } log.LogInfo($"{slaves.Count} slaves configured."); Slaves = slaves.AsReadOnly(); var items = new List <CronItem>(); foreach (var entry in config.ReadSection("cron", false)) { var line = entry.Trim(new char[] { '\t', ' ' }); if (line.Contains("#")) { line = line.Substring(0, line.IndexOf('#')).Trim(new char[] { '\t', ' ' }); } if (line.Length == 0) { continue; } try { items.Add(CronItem.Parse(line)); } catch (Exception ex) { log.LogError(ex, string.Format("Error while loading crontab line #{0} {1}", items.Count, line)); } finally { } } log.LogInfo($"{items.Count} cron tab entries configured."); Items = items.AsReadOnly(); }
/// <summary>Initializes a new instance of the <see cref="MusicDataBase"/> class.</summary> /// <param name="rootFolder">The root folder.</param> /// <exception cref="FileNotFoundException">WebFolder missing!</exception> /// <exception cref="Exception"></exception> public MusicDataBase(string rootFolder) { this.LogVerbose("Initializing MusicDataBase"); RootFolder = rootFolder; ConfigFileName = FileSystem.Combine(rootFolder, "JukeBob.ini"); this.LogVerbose("Loading configuration {0}", ConfigFileName); Config = IniReader.FromFile(ConfigFileName); if (!Config.HasSection("MusicDataBase")) { throw new FileNotFoundException($"Missing configuration {ConfigFileName}!", ConfigFileName); } foreach (string folder in Config.ReadSection("MusicFolders", true)) { string f = Path.GetFullPath(folder); this.LogVerbose("MusicFolder {0} => {1}", folder, f); if (!Directory.Exists(f)) { throw new DirectoryNotFoundException(string.Format("MusicFolder {0} not found!", folder)); } MusicFolders.Include(f); } DataBasePath = GetFolderConfig("MusicDataBase", "DatabaseFolder", "database"); this.LogVerbose("Using Database path {0}", DataBasePath); try { ArtistArtFolder = GetFolderConfig("MusicDataBase", "ArtFolder", "art"); this.LogVerbose("ArtistArtFolder {0}", ArtistArtFolder); Directory.CreateDirectory(ArtistArtFolder); CacheFolder = GetFolderConfig("MusicDataBase", "CacheFolder", "cache"); this.LogVerbose("CacheFolder {0}", CacheFolder); Directory.CreateDirectory(CacheFolder); WebFolder = GetFolderConfig("MusicDataBase", "WebFolder", "web"); this.LogVerbose("WebFolder {0}", WebFolder); if (!File.Exists(FileSystem.Combine(WebFolder, "index.cwt"))) { throw new FileNotFoundException("WebFolder missing!"); } } catch (Exception ex) { throw new Exception(string.Format("Could not load configuration from {0}", ConfigFileName), ex); } }
/// <summary> /// Initializes a new instance of the <see cref="IniWriter"/> class. /// </summary> /// <param name="fileName">Name of the file to write to.</param> /// <param name="properties">Encoding properties.</param> public IniWriter(string fileName, IniProperties properties) { Properties = properties.Valid ? properties : IniProperties.Default; FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); if (File.Exists(fileName)) { Load(IniReader.FromFile(fileName)); } else { using (var f = File.Open(fileName, FileMode.OpenOrCreate)) { } } }
/// <summary>Writes the artist ini.</summary> /// <param name="folder">The folder.</param> /// <param name="artist">The artist.</param> /// <exception cref="ArgumentNullException">MusicBrainzArtistGuid</exception> public void WriteArtistIni(MDBFolder folder, MDBArtist artist) { if (artist.MusicBrainzArtistGuid == null) { throw new ArgumentNullException("MusicBrainzArtistGuid"); } string artistIniFile = folder.GetFullPath(this, "artist.ini"); FileSystem.TouchFile(artistIniFile); var ini = IniReader.FromFile(artistIniFile); var writer = new IniWriter(ini); writer.WriteSetting("Artist", "Guid", artist.MusicBrainzArtistGuid.ToString()); var artists = new Set <string>(ini.ReadSection("Artists")); artists.Include(artist.Name); writer.WriteSection("Artists", artists); writer.Save(); }
void Reload() { // only one reload at a time lock (this) { { // multi thread reload check DateTime lastChanged = FileSystem.GetLastWriteTimeUtc(FileName); if (lastChanged == LastChanged) { return; } } Trace.TraceInformation("Reloading template {0}", FileName); // read config var config = IniReader.FromFile(FileName); { LastChanged = FileSystem.GetLastWriteTimeUtc(FileName); int v = config.ReadInt32("CaveWebTemplate", "Version"); if (v != 1) { throw new WebServerException(WebError.InternalServerError, 0, $"{FileName} invalid template version!"); } } // build function list { var functions = new List <Func>(); foreach (string function in config.ReadSection("Functions", true)) { var f = new Func { Name = function, Method = server.FindMethod(function), }; if (f.Method == null) { throw new WebServerException(WebError.InternalServerError, 0, $"{FileName} invalid function call {function}!"); } var list = new List <WebTemplateParameter>(); foreach (string parameter in config.ReadSection(function, true)) { var i = Option.Parse(parameter); if (i.Name.StartsWith("?")) { switch (i.Name) { case "?IfParametersPresent": foreach (string neededParam in i.Value.Split(',')) { if (neededParam.Trim().Length == 0) { continue; } f.NeededParameters.Include(neededParam); } break; default: throw new NotImplementedException($"Option {i} is not implemented!"); } continue; } f.Parameters.Add(i.Name, i.Value); list.Add(new WebTemplateParameter() { ID = CaveSystemData.CalculateID(function + i.Name), FunctionName = function, ParameterAtFunction = i.Name, ParameterAtTemplate = i.Value, }); } f.ParameterDescriptions = list.ToArray(); functions.Add(f); } this.functions = functions.ToArray(); } // build content { var content = new List <WebContentFile>(); // main file is always first content file string master = config.ReadSetting("CaveWebTemplate", "Master"); if (master == null) { master = Path.GetFileNameWithoutExtension(FileName) + ".html"; } string folder = Path.GetDirectoryName(FileName); foreach (string contentFile in new string[] { master }) { content.Add(new WebContentFile(server, folder, contentFile)); } foreach (string contentFile in config.ReadSection("Content", true)) { content.Add(new WebContentFile(server, folder, contentFile)); } if (server.EnableStaticTemplates) { staticData = BuildStaticData(content.ToArray()); } else { this.content = content.ToArray(); } } } }
csDebber(string file) { SystemConsole.WriteLine("Building debian package defined at <cyan>{0}", file); Directory.SetCurrentDirectory(Path.GetDirectoryName(file)); ini = IniReader.FromFile(file); }