forked from WolvenKit/WolvenKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameUnitTest.cs
92 lines (76 loc) · 3.4 KB
/
GameUnitTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Catel.IoC;
using CP77.CR2W.Archive;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WolvenKit.Common.Oodle;
using WolvenKit.Common.Services;
namespace CP77.MSTests
{
[TestClass]
public class GameUnitTest
{
private const string GameDirectorySetting = "GameDirectory";
private const string WriteToFileSetting = "WriteToFile";
private static ArchiveManager bm;
internal static Dictionary<string, List<FileEntry>> GroupedFiles;
private static IConfigurationRoot _config;
internal const string TestResultsDirectory = "_CR2WTestResults";
private static string _gameDirectoryPath;
internal static bool WriteToFile;
protected static void Setup(TestContext context)
{
Console.WriteLine("BaseTestClass.BaseTestInitialize()");
_config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
// check for CP77_DIR environment variable first
// overrides hardcoded appsettings.json
var CP77_DIR = System.Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(CP77_DIR) && new DirectoryInfo(CP77_DIR).Exists)
_gameDirectoryPath = CP77_DIR;
else
_gameDirectoryPath = _config.GetSection(GameDirectorySetting).Value;
if (string.IsNullOrEmpty(_gameDirectoryPath))
throw new ConfigurationErrorsException($"'{GameDirectorySetting}' is not configured");
var gameDirectory = new DirectoryInfo(_gameDirectoryPath);
if (!gameDirectory.Exists)
throw new ConfigurationErrorsException($"'{GameDirectorySetting}' is not a valid directory");
// copy oodle dll
var gameBinDir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "bin", "x64"));
var oodleInfo = new FileInfo(Path.Combine(gameBinDir.FullName, "oo2ext_7_win64.dll"));
if (!oodleInfo.Exists)
throw new DecompressionException("Could not find oo2ext_7_win64.dll.");
var ass = AppDomain.CurrentDomain.BaseDirectory;
var destFileName = Path.Combine(ass, "oo2ext_7_win64.dll");
if (!File.Exists(destFileName))
oodleInfo.CopyTo(destFileName);
WriteToFile = Boolean.Parse(_config.GetSection(WriteToFileSetting).Value);
ServiceLocator.Default.RegisterType<ILoggerService, LoggerService>();
ServiceLocator.Default.RegisterType<IHashService, HashService>();
var hashService = ServiceLocator.Default.ResolveType<IHashService>();
hashService.ReloadLocally();
DirectoryInfo gameArchiveDir;
try
{
gameArchiveDir = new DirectoryInfo(Path.Combine(gameDirectory.FullName, "archive", "pc", "content"));
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
bm = new ArchiveManager(gameArchiveDir);
GroupedFiles = bm.GroupedFiles;
}
}
}