This repository was archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented INI and Renderer read functions
- Loading branch information
Showing
4 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
Copyright (C) 2019 erri120 | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
* This file contains parts of the Oblivion Mod Manager licensed under GPLv2 | ||
* and has been modified for use in this OMODFramework | ||
* Original source: https://www.nexusmods.com/oblivion/mods/2097 | ||
* GPLv2: https://opensource.org/licenses/gpl-2.0.php | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace OMODFramework.Classes | ||
{ | ||
internal static class OblivionINI | ||
{ | ||
internal static string GetINIValue(string section, string name) | ||
{ | ||
var result = ""; | ||
GetINISection(section, out var list); | ||
if(list == null) | ||
throw new OMODFrameworkException($"Oblivion.ini section {section} does not exist!"); | ||
|
||
list.Where(s => s.Trim().ToLower().StartsWith($"{name.ToLower()}=")).Do(s => | ||
{ | ||
var res = s.Substring(s.IndexOf('=') + 1).Trim(); | ||
var i = res.IndexOf(';'); | ||
if (i != -1) | ||
res = res.Substring(0, i - 1); | ||
result = res; | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
internal static void GetINISection(string section, out List<string> list) | ||
{ | ||
if(string.IsNullOrWhiteSpace(Framework.OblivionINIFile)) | ||
throw new OMODFrameworkException("OblivionINI.GetINISection requires a path to oblivion.ini"); | ||
|
||
var contents = new List<string>(); | ||
var inSection = false; | ||
using (var sr = new StreamReader(File.OpenRead(Framework.OblivionINIFile), Encoding.UTF8)) | ||
{ | ||
try | ||
{ | ||
while (sr.Peek() != -1) | ||
{ | ||
var s = sr.ReadLine(); | ||
if (s == null) | ||
break; | ||
if (inSection) | ||
{ | ||
if (s.Trim().StartsWith("[") && s.Trim().EndsWith("]")) break; | ||
contents.Add(s); | ||
} | ||
else | ||
{ | ||
if (s.Trim().ToLower() == section) | ||
inSection = true; | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new OMODFrameworkException($"Could not read from oblivion.ini at {Framework.OblivionINIFile}\n{e}"); | ||
} | ||
} | ||
|
||
if (!inSection) list = null; | ||
list = contents; | ||
} | ||
} | ||
|
||
internal static class OblivionRenderInfo | ||
{ | ||
internal static string GetInfo(string s) | ||
{ | ||
if(string.IsNullOrWhiteSpace(Framework.OblivionRenderInfoFile)) | ||
throw new OMODFrameworkException("OblivionRenderInfo.GetInfo requires a path to the RenderInfo.txt file"); | ||
|
||
var result = $"Value {s} not found"; | ||
|
||
try | ||
{ | ||
var lines = File.ReadAllLines(Framework.OblivionRenderInfoFile); | ||
lines.Where(t => t.Trim().ToLower().StartsWith(s)).Do(t => | ||
{ | ||
var split = t.Split(':'); | ||
if (split.Length != 2) result = "-1"; | ||
result = split[1].Trim(); | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new OMODFrameworkException($"Could not read from RenderInfo.txt file at {Framework.OblivionRenderInfoFile}\n{e}"); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters