Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from erri120/settings
Browse files Browse the repository at this point in the history
Settings
  • Loading branch information
erri120 authored Dec 3, 2019
2 parents 734e972 + d532184 commit c20c115
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 271 deletions.
17 changes: 11 additions & 6 deletions OMODFramework.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ internal class Program
private static void Main(string[] args)
{
// set the temp folder if you don't want it at %temp%/OMODFramework/
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");
Framework.Settings.TempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");

Framework.OblivionINIFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Framework.Settings.ScriptExecutionSettings.OblivionINIPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Oblivion.ini");

Framework.CodeProgress = new Progress();
Framework.Settings.CodeProgress = new Progress();

if(Directory.Exists(Framework.TempDir))
var settings = new FrameworkSettings()
{

};

if(Directory.Exists(Framework.Settings.TempPath))
Framework.CleanTempDir();

var omod = new OMOD("DarNified UI 1.3.2.omod");

var data = omod.GetDataFiles(); // extracts all data files
var plugins = omod.GetPlugins(); // extracts all plugins
var data = omod.GetDataFiles().Result; // extracts all data files
var plugins = omod.GetPlugins().Result; // extracts all plugins

var scriptFunctions = new ScriptFunctions();
var srd = omod.RunScript(scriptFunctions, data, plugins);
Expand Down
6 changes: 3 additions & 3 deletions OMODFramework.Test/ATest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public abstract class ATest
[TestInitialize]
public void Setup()
{
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");
Framework.Settings.TempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");

if (!Directory.Exists(Framework.TempDir))
Directory.CreateDirectory(Framework.TempDir);
if (!Directory.Exists(Framework.Settings.TempPath))
Directory.CreateDirectory(Framework.Settings.TempPath);
else
Framework.CleanTempDir();

Expand Down
2 changes: 1 addition & 1 deletion OMODFramework.Test/CompressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CompressionTests
[TestInitialize]
public void Setup()
{
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");
Framework.Settings.TempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");

File.WriteAllText(HelloFile, "Hello World!");
}
Expand Down
8 changes: 4 additions & 4 deletions OMODFramework.Test/EndToEndTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class EndToEndTest
[TestInitialize]
public void Setup()
{
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");
Framework.Settings.TempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir");

if (!Directory.Exists(Framework.TempDir))
Directory.CreateDirectory(Framework.TempDir);
if (!Directory.Exists(Framework.Settings.TempPath))
Directory.CreateDirectory(Framework.Settings.TempPath);
else
Framework.CleanTempDir();

OMODFile = Path.Combine(Framework.TempDir, "ILoveTesting.omod");
OMODFile = Path.Combine(Framework.Settings.TempPath, "ILoveTesting.omod");
ModFiles = new List<string>();
FolderStructure = new List<string>();

Expand Down
8 changes: 4 additions & 4 deletions OMODFramework.Test/OMODTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public void TestCreation()
{
if(File.Exists("test.omod"))
File.Delete("test.omod");
Directory.CreateDirectory(Path.Combine(Framework.TempDir, "text_files"));
Directory.CreateDirectory(Path.Combine(Framework.Settings.TempPath, "text_files"));

var file1 = Path.Combine(Framework.TempDir, "file.txt");
var file2 = Path.Combine(Framework.TempDir, "file2.txt");
var file3 = Path.Combine(Framework.TempDir, "text_files", "file3.txt");
var file1 = Path.Combine(Framework.Settings.TempPath, "file.txt");
var file2 = Path.Combine(Framework.Settings.TempPath, "file2.txt");
var file3 = Path.Combine(Framework.Settings.TempPath, "text_files", "file3.txt");

var text1 = "This is some text";
var text2 = "This is more text";
Expand Down
8 changes: 4 additions & 4 deletions OMODFramework/Classes/CompressionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void NextFile()
_currentOutputStream?.Close();

_currentOutputStream = File.Create(!Utils.IsSafeFileName(_currentFile)
? Path.Combine(Framework.TempDir, "IllegalFile")
? Path.Combine(Framework.Settings.TempPath, "IllegalFile")
: Path.Combine(BaseDirectory, _currentFile));
_written = 0;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public override void Close()
_currentOutputStream?.Close();

_currentOutputStream = File.Create(!Utils.IsSafeFileName(_currentFile)
? Path.Combine(Framework.TempDir, "IllegalFile")
? Path.Combine(Framework.Settings.TempPath, "IllegalFile")
: Path.Combine(BaseDirectory, _currentFile));
}

Expand Down Expand Up @@ -399,7 +399,7 @@ protected override string DecompressAll(Stream fileList, Stream compressedStream

compressedStream.Read(buffer, 0, 5);
decoder.SetDecoderProperties(buffer);
var progress = Framework.CodeProgress;
var progress = Framework.Settings.CodeProgress;
progress?.Init(sfs.Length, false);
try
{
Expand Down Expand Up @@ -450,7 +450,7 @@ protected override FileStream CompressAll(List<string> filePaths, CompressionLev

var fs = Utils.CreateTempFile();
coder.WriteCoderProperties(fs);
var progress = Framework.CodeProgress;
var progress = Framework.Settings.CodeProgress;
progress?.Init(sfs.Length, true);

try
Expand Down
6 changes: 3 additions & 3 deletions OMODFramework/Classes/OMOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public OMOD(string path)
using (var br = new BinaryReader(configStream))
{
var fileVersion = br.ReadByte();
if(fileVersion > Framework.CurrentOmodVersion && !Framework.IgnoreVersion)
if(fileVersion > Framework.Settings.CurrentOMODVersion && !Framework.Settings.IgnoreVersionCheck)
throw new OMODFrameworkException($"{FileName} was created with a newer version of OBMM and could not be loaded!");

ModName = br.ReadString();
Expand Down Expand Up @@ -227,7 +227,7 @@ public static void CreateOMOD(OMODCreationOptions ops, string omodFileName)
ze = new ZipEntry("config");
zipStream.PutNextEntry(ze);

omodStream.Write(Framework.CurrentOmodVersion);
omodStream.Write(Framework.Settings.CurrentOMODVersion);
omodStream.Write(ops.Name);
omodStream.Write(ops.MajorVersion);
omodStream.Write(ops.MinorVersion);
Expand Down Expand Up @@ -430,7 +430,7 @@ private async Task<Stream> ExtractWholeFile(ZipEntry ze, string path)
var file = ModFile.GetInputStream(ze);
Stream tempStream;

if (path != null || ze.Size > Framework.MaxMemoryStreamSize)
if (path != null || ze.Size > Framework.Settings.MaxMemoryStreamSize)
tempStream = Utils.CreateTempFile(out path);
else
tempStream = new MemoryStream((int)ze.Size);
Expand Down
12 changes: 6 additions & 6 deletions OMODFramework/Classes/Oblivion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ internal static string GetINIValue(string section, string name)

internal static void GetINISection(string section, out List<string> list)
{
if(string.IsNullOrWhiteSpace(Framework.OblivionINIFile))
if(string.IsNullOrWhiteSpace(Framework.Settings.ScriptExecutionSettings.OblivionINIPath))
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))
using (var sr = new StreamReader(File.OpenRead(Framework.Settings.ScriptExecutionSettings.OblivionINIPath), Encoding.UTF8))
{
try
{
Expand All @@ -81,7 +81,7 @@ internal static void GetINISection(string section, out List<string> list)
}
catch (Exception e)
{
throw new OMODFrameworkException($"Could not read from oblivion.ini at {Framework.OblivionINIFile}\n{e}");
throw new OMODFrameworkException($"Could not read from oblivion.ini at {Framework.Settings.ScriptExecutionSettings.OblivionINIPath}\n{e}");
}
}

Expand All @@ -94,14 +94,14 @@ internal static class OblivionRenderInfo
{
internal static string GetInfo(string s)
{
if(string.IsNullOrWhiteSpace(Framework.OblivionRenderInfoFile))
if(string.IsNullOrWhiteSpace(Framework.Settings.ScriptExecutionSettings.OblivionRendererInfoPath))
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);
var lines = File.ReadAllLines(Framework.Settings.ScriptExecutionSettings.OblivionRendererInfoPath);
lines.Where(t => t.Trim().ToLower().StartsWith(s)).Do(t =>
{
var split = t.Split(':');
Expand All @@ -111,7 +111,7 @@ internal static string GetInfo(string s)
}
catch (Exception e)
{
throw new OMODFrameworkException($"Could not read from RenderInfo.txt file at {Framework.OblivionRenderInfoFile}\n{e}");
throw new OMODFrameworkException($"Could not read from RenderInfo.txt file at {Framework.Settings.ScriptExecutionSettings.OblivionRendererInfoPath}\n{e}");
}

return result;
Expand Down
Loading

0 comments on commit c20c115

Please sign in to comment.