-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (81 loc) · 2.95 KB
/
Program.cs
File metadata and controls
98 lines (81 loc) · 2.95 KB
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
93
94
95
96
97
using CommandLine;
using Gnomoria.ContentExtractor.Extensions;
using NLog;
using SevenZip;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Reflection;
namespace Gnomoria.ContentExtractor
{
#if WINDOWS || XBOX
static class Program
{
static Logger logger = LogManager.GetCurrentClassLogger();
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
var options = new Options();
if (!Parser.Default.ParseArguments(args, options))
{
logger.Error("Invalid arguments");
return;
}
if (!EnsureOptions(options))
return;
var sevenZipPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"lib\7z.dll");
SevenZipExtractor.SetLibraryPath(sevenZipPath);
SevenZipCompressor.SetLibraryPath(sevenZipPath);
using (Game game = new Game(options))
{
game.Run();
}
}
private static bool EnsureOptions(Options options)
{
if (!EnsureDataType(options))
return false;
if (options.Source == null)
{
var pathMap = new Dictionary<DataType, string>
{
{ DataType.Data, @"Data" },
{ DataType.Skin, @"UI" }
};
options.Source = Path.Combine(ConfigurationManager.AppSettings["ContentRoot"], pathMap[options.DataType]);
logger.Info("Source not specified. Using default '{0}'", options.Source);
}
options.Source = Environment.ExpandEnvironmentVariables(options.Source);
if (!Directory.Exists(options.Source) && !File.Exists(options.Source))
{
logger.Error("Invalid source specified '{0}'", options.Source);
return false;
}
if (Directory.Exists(options.Source))
options.Source = options.Source.EnsureEndsWith(Path.DirectorySeparatorChar);
logger.Debug("Options: {0}", options.Dump());
return true;
}
private static bool EnsureDataType(Options options)
{
if (options.DataType != DataType.Unknown)
return true;
if (options.Source != null)
{
// try to guess it from source path
if (options.Source.Contains(@"Gnomoria\Content\Data"))
options.DataType = DataType.Data;
if (options.Source.Contains(@"Gnomoria\Content\UI"))
options.DataType = DataType.Skin;
}
if (options.DataType != DataType.Unknown)
return true;
logger.Error("Unknown data type");
return false;
}
}
#endif
}