This repository has been 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.
Created abstract class for downloading oblivion mods
- Loading branch information
Showing
4 changed files
with
259 additions
and
60 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,87 @@ | ||
/* | ||
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/>. | ||
*/ | ||
|
||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Reflection; | ||
using ICSharpCode.SharpZipLib.Zip; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Pathoschild.FluentNexus; | ||
using File = Alphaleonis.Win32.Filesystem.File; | ||
using Path = Alphaleonis.Win32.Filesystem.Path; | ||
|
||
namespace OMODFramework.Test | ||
{ | ||
public abstract class DownloadTest | ||
{ | ||
private string _apiKey; | ||
private NexusClient _client; | ||
|
||
public abstract string DownloadFileName { get; set; } | ||
public abstract string FileName { get; set; } | ||
public abstract int ModID { get; set; } | ||
public abstract int FileID { get; set; } | ||
|
||
[TestInitialize] | ||
protected void Setup() | ||
{ | ||
Framework.TempDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestTempDir"); | ||
|
||
if (File.Exists(DownloadFileName) && File.Exists(FileName)) | ||
return; | ||
|
||
if(!File.Exists("nexus_api_key.txt")) | ||
throw new Exception("Nexus API Key file does not exist!"); | ||
|
||
_apiKey = File.ReadAllText("nexus_api_key.txt"); | ||
|
||
_client = new NexusClient(_apiKey, "OMODFramework Unit Tests", "0.0.1"); | ||
|
||
var limits = _client.GetRateLimits().Result; | ||
|
||
if(limits.IsBlocked() && !File.Exists(DownloadFileName)) | ||
throw new Exception("Rate limit blocks all Nexus Connections!"); | ||
|
||
var downloadLinks = _client.ModFiles.GetDownloadLinks("oblivion", ModID, FileID).Result; | ||
|
||
using (var client = new WebClient()) | ||
{ | ||
client.DownloadFile(downloadLinks[0].Uri, DownloadFileName); | ||
} | ||
|
||
if(File.Exists(FileName)) | ||
return; | ||
|
||
using (var zipStream = new ZipFile(File.OpenRead(DownloadFileName))) | ||
using (var fs = new FileStream(FileName, FileMode.CreateNew)) | ||
{ | ||
foreach (ZipEntry ze in zipStream) | ||
{ | ||
if(ze.IsFile && ze.Name.ToLower().Contains("omod")) | ||
zipStream.GetInputStream(ze).CopyTo(fs); | ||
} | ||
} | ||
} | ||
|
||
[TestCleanup] | ||
protected void Cleanup() | ||
{ | ||
Framework.CleanTempDir(true); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
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/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using OMODFramework.Scripting; | ||
|
||
namespace OMODFramework.Test | ||
{ | ||
internal class ScriptFunctions : IScriptFunctions | ||
{ | ||
public void Warn(string msg) | ||
{ | ||
Debug.WriteLine($"[Warning]: {msg}"); | ||
} | ||
|
||
public void Message(string msg) | ||
{ | ||
Debug.WriteLine($"[Message]: {msg}"); | ||
} | ||
|
||
public void Message(string msg, string title) | ||
{ | ||
Debug.WriteLine($"[Message]: {title} - {msg}"); | ||
} | ||
|
||
public List<int> Select(List<string> items, string title, bool isMultiSelect, List<string> previews, List<string> descriptions) | ||
{ | ||
Debug.WriteLine($"[Select]: {title} multi: {isMultiSelect}"); | ||
for (var i = 0; i < items.Count; i++) | ||
{ | ||
var preview = previews?[i] != null ? previews[i] : "empty"; | ||
var description = descriptions?[i] != null ? descriptions[i] : "empty"; | ||
Debug.Write($"Items: {items[i]} | preview: {preview} | description: {description}"); | ||
} | ||
return new List<int>{0}; | ||
} | ||
|
||
public string InputString(string title, string initialText, bool useRTF) | ||
{ | ||
Debug.WriteLine($"[InputString]: {title}, text: {initialText}, rtf: {useRTF}"); | ||
return "Hello World"; | ||
} | ||
|
||
public int DialogYesNo(string title) | ||
{ | ||
Debug.WriteLine($"[DialogYesNo]: {title}"); | ||
return 1; | ||
} | ||
|
||
public int DialogYesNo(string title, string message) | ||
{ | ||
Debug.WriteLine($"[DialogYesNo]: {title} - {message}"); | ||
return 1; | ||
} | ||
|
||
public void DisplayImage(string path, string title) | ||
{ | ||
Debug.WriteLine($"[Image]: {title} - {path}"); | ||
} | ||
|
||
public void DisplayText(string text, string title) | ||
{ | ||
Debug.WriteLine($"[Text]: {title} - {text}"); | ||
} | ||
|
||
public void Patch(string from, string to) | ||
{ | ||
Debug.WriteLine($"[Patch]: {from} - {to}"); | ||
} | ||
|
||
public string ReadOblivionINI(string section, string name) | ||
{ | ||
Debug.WriteLine($"[ReadOblivionINI]: {section} - {name}"); | ||
return ""; | ||
} | ||
|
||
public string ReadRendererInfo(string name) | ||
{ | ||
Debug.WriteLine($"[ReadRendererInfo]: {name}"); | ||
return ""; | ||
} | ||
|
||
public bool DataFileExists(string path) | ||
{ | ||
Debug.WriteLine($"[DataFileExists]: {path}"); | ||
return false; | ||
} | ||
|
||
public bool HasScriptExtender() | ||
{ | ||
return true; | ||
} | ||
|
||
public bool HasGraphicsExtender() | ||
{ | ||
return false; | ||
} | ||
|
||
public Version ScriptExtenderVersion() | ||
{ | ||
return new Version(0, 0, 21, 4); | ||
} | ||
|
||
public Version GraphicsExtenderVersion() | ||
{ | ||
return new Version(""); | ||
} | ||
|
||
public Version OblivionVersion() | ||
{ | ||
return new Version(1, 2, 0, 416); | ||
} | ||
} | ||
} |
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,37 @@ | ||
/* | ||
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/>. | ||
*/ | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace OMODFramework.Test | ||
{ | ||
public class ScriptTest : DownloadTest | ||
{ | ||
// testing with NoMaaM Breathing Idles from | ||
// https://www.nexusmods.com/oblivion/mods/40462 | ||
public override string DownloadFileName { get; set; } = "NoMaaM Breathing Idles V1 OMOD-40462-1-0.omod"; | ||
public override string FileName { get; set; } = "NoMaaM Breathing Idles V1 OMOD-40462-1-0.omod"; | ||
public override int ModID { get; set; } = 10763; | ||
public override int FileID { get; set; } = 85415; | ||
|
||
[TestMethod] | ||
public void TestOBMMScript() | ||
{ | ||
var omod = new OMOD(FileName); | ||
} | ||
} | ||
} |