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

Commit

Permalink
Implemented all but BSA related DotNetFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Nov 30, 2019
1 parent ff82b62 commit 394b42d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 23 additions & 2 deletions OMODFramework/Scripting/DotNetScriptFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ public byte[] ReadDataFile(string file)

public byte[] ReadExistingDataFile(string file)
{
throw new NotImplementedException();
CheckPathSafety(file);
return _handler.ScriptFunctions.ReadExistingDataFile(file);
}

public byte[] GetDataFileFromBSA(string file)
Expand All @@ -794,7 +795,27 @@ public byte[] GetDataFileFromBSA(string bsa, string file)

public void GenerateNewDataFile(string file, byte[] data)
{
throw new NotImplementedException();
CheckPathSafety(file);
var path = Path.Combine(_dataFiles, file);
if (!File.Exists(path))
{
var ext = Path.GetExtension(path.ToLower());
if(ext == ".esm" || ext == ".esp")
throw new ScriptingException("Copied data files cannot have a .esp or .esm file extension");
_srd.CopyDataFiles.RemoveWhere(s => s.CopyTo == file.ToLower());
_srd.CopyDataFiles.Add(new ScriptCopyDataFile(file, file));
}

if (!Directory.Exists(Path.GetDirectoryName(path)))
Directory.CreateDirectory(Path.GetDirectoryName(path));
try
{
File.WriteAllBytes(path, data);
}
catch (Exception e)
{
throw new OMODFrameworkException($"Could not write all bytes to file at '{path}'\n{e}");
}
}

public void CancelDataFileCopy(string file)
Expand Down
7 changes: 7 additions & 0 deletions OMODFramework/Scripting/IScriptFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ List<int> Select(
/// </summary>
/// <returns></returns>
HashSet<string> GetActiveOMODNames();

/// <summary>
/// Use System.IO.File.ReadAllBytes to read the bytes of a file located inside the data folder
/// </summary>
/// <param name="file">Relative path to the file inside the data folder</param>
/// <returns></returns>
byte[] ReadExistingDataFile(string file);
}

/// <summary>
Expand Down

0 comments on commit 394b42d

Please sign in to comment.