2016-03-20 09:01:04 +00:00
|
|
|
|
/*
|
|
|
|
|
_ _ _ ____ _ _____
|
|
|
|
|
/ \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
|
|
|
|
/ _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
|
|
|
|
/ ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
|
|
|
|
/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
|
|
|
|
|
|
|
|
|
Copyright 2015-2016 Łukasz "JustArchi" Domeradzki
|
|
|
|
|
Contact: JustArchi@JustArchi.net
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-03-20 04:27:30 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ConfigGenerator {
|
|
|
|
|
internal static class Program {
|
|
|
|
|
internal const string ASF = "ASF";
|
|
|
|
|
internal const string ConfigDirectory = "config";
|
|
|
|
|
internal const string GlobalConfigFile = ASF + ".json";
|
|
|
|
|
|
|
|
|
|
private const string ASFDirectory = "ArchiSteamFarm";
|
|
|
|
|
|
2016-04-19 10:23:24 +00:00
|
|
|
|
private static readonly string ExecutableDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
2016-03-20 04:27:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
private static void Main() {
|
|
|
|
|
Init();
|
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
|
Application.Run(new MainForm());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Init() {
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
|
|
|
|
|
TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler;
|
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(ExecutableDirectory);
|
|
|
|
|
|
|
|
|
|
// Allow loading configs from source tree if it's a debug build
|
|
|
|
|
if (Debugging.IsDebugBuild) {
|
|
|
|
|
|
|
|
|
|
// Common structure is bin/(x64/)Debug/ArchiSteamFarm.exe, so we allow up to 4 directories up
|
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
|
Directory.SetCurrentDirectory("..");
|
2016-05-13 04:32:42 +00:00
|
|
|
|
if (!Directory.Exists(ASFDirectory)) {
|
|
|
|
|
continue;
|
2016-03-20 04:27:30 +00:00
|
|
|
|
}
|
2016-05-13 04:32:42 +00:00
|
|
|
|
|
|
|
|
|
Directory.SetCurrentDirectory(ASFDirectory);
|
|
|
|
|
break;
|
2016-03-20 04:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If config directory doesn't exist after our adjustment, abort all of that
|
|
|
|
|
if (!Directory.Exists(ConfigDirectory)) {
|
|
|
|
|
Directory.SetCurrentDirectory(ExecutableDirectory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-13 04:32:42 +00:00
|
|
|
|
if (Directory.Exists(ConfigDirectory)) {
|
|
|
|
|
return;
|
2016-03-20 04:27:30 +00:00
|
|
|
|
}
|
2016-05-13 04:32:42 +00:00
|
|
|
|
|
2016-05-30 00:06:04 +00:00
|
|
|
|
Logging.LogGenericErrorWithoutStacktrace("Config directory could not be found!");
|
2016-05-13 04:32:42 +00:00
|
|
|
|
Environment.Exit(1);
|
2016-03-20 04:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args) {
|
2016-05-29 23:57:06 +00:00
|
|
|
|
if ((sender == null) || (args == null) || (args.ExceptionObject == null)) {
|
|
|
|
|
Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.ExceptionObject));
|
2016-03-20 04:27:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logging.LogGenericException((Exception) args.ExceptionObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UnobservedTaskExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) {
|
2016-05-29 23:57:06 +00:00
|
|
|
|
if ((sender == null) || (args == null) || (args.Exception == null)) {
|
|
|
|
|
Logging.LogNullError(nameof(sender) + " || " + nameof(args) + " || " + nameof(args.Exception));
|
2016-03-20 04:27:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logging.LogGenericException(args.Exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|