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

Commit

Permalink
Updated Framework to use new Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Dec 3, 2019
1 parent 0a90cc7 commit b29eba1
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 106 deletions.
5 changes: 5 additions & 0 deletions OMODFramework.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ private static void Main(string[] args)

Framework.CodeProgress = new Progress();

var settings = new FrameworkSettings()
{

};

if(Directory.Exists(Framework.TempDir))
Framework.CleanTempDir();

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
5 changes: 5 additions & 0 deletions OMODFramework/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public class FrameworkSettings
/// </summary>
public string DllPath = Assembly.GetExecutingAssembly().Location;

/// <summary>
/// Custom code progress class for displaying the progress of compression/decompression
/// </summary>
public ICodeProgress CodeProgress;

/// <summary>
/// Settings used for Script execution
/// </summary>
Expand Down
53 changes: 19 additions & 34 deletions OMODFramework/Scripting/DotNetScriptFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public bool DataFileExists(string path)

public Version GetOBMMVersion()
{
return new Version(Framework.MajorVersion, Framework.MinorVersion, Framework.BuildNumber, 0);
return new Version(Framework.Settings.MajorVersion, Framework.Settings.MinorVersion, Framework.Settings.BuildNumber, 0);
}

public Version GetOBSEVersion()
Expand Down Expand Up @@ -707,32 +707,22 @@ public string InputString(string title, string initial)

public string ReadINI(string section, string value)
{
switch (Framework.CurrentReadINIMethod)
{
case Framework.ReadINIMethod.ReadOriginalINI:
return OblivionINI.GetINIValue(section, value);
case Framework.ReadINIMethod.ReadWithInterface:
var s = _handler.ScriptFunctions.ReadOblivionINI(section, value);
return s ?? throw new OMODFrameworkException(
"Could not read the oblivion.ini file using the function IScriptFunctions.ReadOblivionINI");
default:
throw new OMODFrameworkException("Unknown ReadINIMethod for Framework.CurrentReadINIMethod!");
}
if (!Framework.Settings.ScriptExecutionSettings.ReadINIWithInterface)
return OblivionINI.GetINIValue(section, value);

var s = _handler.ScriptFunctions.ReadOblivionINI(section, value);
return s ?? throw new OMODFrameworkException(
"Could not read the oblivion.ini file using the function IScriptFunctions.ReadOblivionINI");
}

public string ReadRendererInfo(string value)
{
switch (Framework.CurrentReadINIMethod)
{
case Framework.ReadINIMethod.ReadOriginalINI:
return OblivionRenderInfo.GetInfo(value);
case Framework.ReadINIMethod.ReadWithInterface:
var s = _handler.ScriptFunctions.ReadRendererInfo(value);
return s ?? throw new OMODFrameworkException(
"Could not read the RenderInfo.txt file using the function IScriptFunctions.ReadRendererInfo");
default:
throw new OMODFrameworkException("Unknown ReadRendererMethod for Framework.CurrentReadRendererMethod!");
}
if (!Framework.Settings.ScriptExecutionSettings.ReadRendererInfoWithInterface)
return OblivionRenderInfo.GetInfo(value);

var s = _handler.ScriptFunctions.ReadRendererInfo(value);
return s ?? throw new OMODFrameworkException(
"Could not read the RenderInfo.txt file using the function IScriptFunctions.ReadRendererInfo");
}

public void EditXMLLine(string file, int line, string value)
Expand Down Expand Up @@ -813,17 +803,12 @@ public byte[] GetDataFileFromBSA(string bsa, string file)

private byte[] GetFromBSA(string bsa, string file)
{
switch (Framework.CurrentBSAHandling)
{
case Framework.BSAHandling.OriginalOBMM:
return bsa == null ? BSAArchive.GetFileFromBSA(file) : BSAArchive.GetFileFromBSA(bsa, file);
case Framework.BSAHandling.WithInterface:
return bsa == null
? _handler.ScriptFunctions.GetDataFileFromBSA(file)
: _handler.ScriptFunctions.GetDataFileFromBSA(bsa, file);
default:
throw new OMODFrameworkException("Unknown BSAHandling for Framework.CurrentBSAHandling!");
}
if(!Framework.Settings.ScriptExecutionSettings.HandleBSAsWithInterface)
return bsa == null ? BSAArchive.GetFileFromBSA(file) : BSAArchive.GetFileFromBSA(bsa, file);

return bsa == null
? _handler.ScriptFunctions.GetDataFileFromBSA(file)
: _handler.ScriptFunctions.GetDataFileFromBSA(bsa, file);
}

public void GenerateNewDataFile(string file, byte[] data)
Expand Down
4 changes: 2 additions & 2 deletions OMODFramework/Scripting/DotNetScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class DotNetScriptHandler
private static readonly CompilerParameters Params;
private static readonly Evidence Evidence;

private static readonly string ScriptOutputPath = Path.Combine(Framework.TempDir, "dotnetscript.dll");
private static readonly string ScriptOutputPath = Path.Combine(Framework.Settings.TempPath, "dotnetscript.dll");

static DotNetScriptHandler()
{
Expand All @@ -33,7 +33,7 @@ static DotNetScriptHandler()
OutputAssembly = ScriptOutputPath,
ReferencedAssemblies =
{
Framework.DLLPath,
Framework.Settings.DllPath,
"System.dll",
"System.Drawing.dll",
"System.Windows.Forms.dll",
Expand Down
2 changes: 1 addition & 1 deletion OMODFramework/Scripting/OBMMScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ private static bool FunctionIf(IReadOnlyCollection<string> line)
try
{
var v = new Version($"{line.ElementAt(2)}.0");
var v2 = new Version($"{Framework.Version}.0");
var v2 = new Version($"{Framework.Settings.Version}.0");
return line.ElementAt(1) == "VersionGreaterThan" ? v2 > v : v2 < v;
}
catch
Expand Down
88 changes: 38 additions & 50 deletions OMODFramework/Scripting/SharedFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal SharedFunctionsHandler(ScriptType type, ref IScriptFunctions scriptFunc

internal void Warn(string msg)
{
if (!Framework.EnableWarnings)
if (!Framework.Settings.ScriptExecutionSettings.EnableWarnings)
return;

if (_type == ScriptType.OBMMScript)
Expand Down Expand Up @@ -1398,14 +1398,19 @@ private void Work(string from, string to, bool plugin, string dataFilesPath, str
? Path.Combine(pluginPath, from)
: Path.Combine(dataFilesPath, from);

switch (Framework.CurrentPatchMethod)
if (Framework.Settings.ScriptExecutionSettings.PatchWithInterface)
{
case Framework.PatchMethod.CreatePatchGameFolder:
if (string.IsNullOrWhiteSpace(Framework.OblivionGameFolder))
Handler.ScriptFunctions.Patch(pathFrom, to);
}
else
{
if (Framework.Settings.ScriptExecutionSettings.UseSafePatching)
{
if (string.IsNullOrWhiteSpace(Framework.Settings.ScriptExecutionSettings.OblivionGamePath))
throw new OMODFrameworkException(
$"{Framework.OblivionGameFolder} can not be null or whitespace!");
$"{Framework.Settings.ScriptExecutionSettings.OblivionGamePath} can not be null or whitespace!");

var patchFolder = Path.Combine(Framework.OblivionDataFolder, "Patch");
var patchFolder = Path.Combine(Framework.Settings.ScriptExecutionSettings.OblivionDataPath, "Patch");

if (!Directory.Exists(patchFolder))
Directory.CreateDirectory(patchFolder);
Expand All @@ -1414,7 +1419,7 @@ private void Work(string from, string to, bool plugin, string dataFilesPath, str
if (File.Exists(patchPath))
throw new OMODFrameworkException($"The file {patchPath} already exists");

var toDataPath = Path.Combine(Framework.OblivionDataFolder, to);
var toDataPath = Path.Combine(Framework.Settings.ScriptExecutionSettings.OblivionDataPath, to);
DateTime toTimeStamp = default;
if (File.Exists(toDataPath))
{
Expand All @@ -1432,14 +1437,14 @@ private void Work(string from, string to, bool plugin, string dataFilesPath, str
throw new OMODFrameworkException(
$"The file {pathFrom} could not be copied to {patchPath}\n{e}");
}

break;
case Framework.PatchMethod.OverwriteGameFolder:
if (string.IsNullOrWhiteSpace(Framework.OblivionGameFolder))
}
else
{
if (string.IsNullOrWhiteSpace(Framework.Settings.ScriptExecutionSettings.OblivionGamePath))
throw new OMODFrameworkException(
$"{Framework.OblivionGameFolder} can not be null or whitespace!");
$"{Framework.Settings.ScriptExecutionSettings.OblivionGamePath} can not be null or whitespace!");

var dataPath = Path.Combine(Framework.OblivionDataFolder, to);
var dataPath = Path.Combine(Framework.Settings.ScriptExecutionSettings.OblivionDataPath, to);
DateTime timeStamp = default;
if (File.Exists(dataPath))
{
Expand All @@ -1464,17 +1469,7 @@ private void Work(string from, string to, bool plugin, string dataFilesPath, str
{
throw new OMODFrameworkException($"The file {pathFrom} could not be moved to {dataPath}\n{e}");
}

break;
case Framework.PatchMethod.CreatePatchInMod:
srd.PatchFiles.RemoveWhere(s => s.CopyTo == to.ToLower());
srd.PatchFiles.Add(new ScriptCopyDataFile(from.ToLower(), to.ToLower()));
break;
case Framework.PatchMethod.PatchWithInterface:
Handler.ScriptFunctions.Patch(pathFrom, to);
break;
default:
throw new OMODFrameworkException("Unknown PatchMethod for Framework.CurrentPatchMethod!");
}
}
}

Expand Down Expand Up @@ -1815,20 +1810,17 @@ internal class FunctionReadINI : SharedFunction

public override void Run(ref IReadOnlyCollection<string> line)
{
switch (Framework.CurrentReadINIMethod)
if (Framework.Settings.ScriptExecutionSettings.ReadINIWithInterface)
{
case Framework.ReadINIMethod.ReadOriginalINI:
OBMMScriptHandler.Variables[line.ElementAt(1)] =
OblivionINI.GetINIValue(line.ElementAt(2), line.ElementAt(3));
break;
case Framework.ReadINIMethod.ReadWithInterface:
var s = Handler.ScriptFunctions.ReadOblivionINI(line.ElementAt(2), line.ElementAt(3));
OBMMScriptHandler.Variables[line.ElementAt(1)] =
s ?? throw new OMODFrameworkException(
"Could not read the oblivion.ini file using the function IScriptFunctions.ReadOblivionINI");
break;
default:
throw new OMODFrameworkException("Unknown ReadINIMethod for Framework.CurrentReadINIMethod!");
var s = Handler.ScriptFunctions.ReadOblivionINI(line.ElementAt(2), line.ElementAt(3));
OBMMScriptHandler.Variables[line.ElementAt(1)] =
s ?? throw new OMODFrameworkException(
"Could not read the oblivion.ini file using the function IScriptFunctions.ReadOblivionINI");
}
else
{
OBMMScriptHandler.Variables[line.ElementAt(1)] =
OblivionINI.GetINIValue(line.ElementAt(2), line.ElementAt(3));
}
}
public override void Execute(ref IReadOnlyCollection<object> args)
Expand All @@ -1848,20 +1840,16 @@ internal class FunctionReadRenderer : SharedFunction

public override void Run(ref IReadOnlyCollection<string> line)
{
switch (Framework.CurrentReadRendererMethod)
if (Framework.Settings.ScriptExecutionSettings.ReadRendererInfoWithInterface)
{
case Framework.ReadRendererMethod.ReadOriginalRenderer:
OBMMScriptHandler.Variables[line.ElementAt(1)] = OblivionRenderInfo.GetInfo(line.ElementAt(2));
break;
case Framework.ReadRendererMethod.ReadWithInterface:
var s = Handler.ScriptFunctions.ReadRendererInfo(line.ElementAt(2));
OBMMScriptHandler.Variables[line.ElementAt(1)] =
s ?? throw new OMODFrameworkException(
"Could not read the RenderInfo.txt file using the function IScriptFunctions.ReadRendererInfo");
break;
default:
throw new OMODFrameworkException(
"Unknown ReadRendererMethod for Framework.CurrentReadRendererMethod!");
var s = Handler.ScriptFunctions.ReadRendererInfo(line.ElementAt(2));
OBMMScriptHandler.Variables[line.ElementAt(1)] =
s ?? throw new OMODFrameworkException(
"Could not read the RenderInfo.txt file using the function IScriptFunctions.ReadRendererInfo");
}
else
{
OBMMScriptHandler.Variables[line.ElementAt(1)] = OblivionRenderInfo.GetInfo(line.ElementAt(2));
}
}
public override void Execute(ref IReadOnlyCollection<object> args)
Expand Down
Loading

0 comments on commit b29eba1

Please sign in to comment.