2016-03-20 10:01:04 +01:00
/ *
_ _ _ ____ _ _____
/ \ _ __ ___ | | __ ( _ ) / ___ | | | _ ___ __ _ _ __ ___ | ___ | __ _ _ __ _ __ ___
/ _ \ | ' __ | / __ | | ' _ \ | | \ ___ \ | __ | / _ \ / _ ` | | ' _ ` _ \ | | _ / _ ` | | ' __ | | ' _ ` _ \
/ ___ \ | | | ( __ | | | | | | ___ ) | | | _ | __ / | ( _ | | | | | | | | | _ | | ( _ | | | | | | | | | |
/ _ / \ _ \ | _ | \ ___ | | _ | | _ | | _ | | ____ / \ __ | \ ___ | \ __ , _ | | _ | | _ | | _ | | _ | \ __ , _ | | _ | | _ | | _ | | _ |
2017-01-02 20:05:21 +01:00
Copyright 2015 - 2017 Ł ukasz "JustArchi" Domeradzki
2016-03-20 10:01:04 +01:00
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-06-27 02:07:27 +02:00
using System.Diagnostics ;
2016-03-20 05:27:30 +01:00
using System.IO ;
using System.Reflection ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
2016-06-27 02:07:27 +02:00
using ArchiSteamFarm ;
2016-03-20 05:27:30 +01:00
namespace ConfigGenerator {
internal static class Program {
2016-08-02 06:04:44 +02:00
private const string ASFExecutableFile = SharedInfo . ASF + ".exe" ;
2016-03-20 05:27:30 +01:00
private static void Init ( ) {
AppDomain . CurrentDomain . UnhandledException + = UnhandledExceptionHandler ;
TaskScheduler . UnobservedTaskException + = UnobservedTaskExceptionHandler ;
2016-07-25 06:08:45 +02:00
string homeDirectory = Path . GetDirectoryName ( Assembly . GetEntryAssembly ( ) . Location ) ;
if ( ! string . IsNullOrEmpty ( homeDirectory ) ) {
Directory . SetCurrentDirectory ( homeDirectory ) ;
2016-03-20 05:27:30 +01:00
2016-07-25 06:08:45 +02:00
// 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-08-02 08:50:31 +02:00
if ( ! Directory . Exists ( SharedInfo . ASFDirectory ) ) {
2016-07-25 06:08:45 +02:00
continue ;
}
2016-05-13 06:32:42 +02:00
2016-08-02 08:50:31 +02:00
Directory . SetCurrentDirectory ( SharedInfo . ASFDirectory ) ;
2016-07-25 06:08:45 +02:00
break ;
}
2016-03-20 05:27:30 +01:00
2016-07-25 06:08:45 +02:00
// If config directory doesn't exist after our adjustment, abort all of that
2016-08-02 06:04:44 +02:00
if ( ! Directory . Exists ( SharedInfo . ConfigDirectory ) ) {
2016-07-25 06:08:45 +02:00
Directory . SetCurrentDirectory ( homeDirectory ) ;
}
2016-03-20 05:27:30 +01:00
}
}
2016-08-02 06:04:44 +02:00
if ( ! Directory . Exists ( SharedInfo . ConfigDirectory ) ) {
2016-06-27 02:07:27 +02:00
Logging . LogGenericErrorWithoutStacktrace ( "Config directory could not be found!" ) ;
Environment . Exit ( 1 ) ;
}
if ( ! File . Exists ( ASFExecutableFile ) ) {
2016-05-13 06:32:42 +02:00
return ;
2016-03-20 05:27:30 +01:00
}
2016-05-13 06:32:42 +02:00
2016-06-27 02:07:27 +02:00
FileVersionInfo asfVersionInfo = FileVersionInfo . GetVersionInfo ( ASFExecutableFile ) ;
Version asfVersion = new Version ( asfVersionInfo . ProductVersion ) ;
2016-07-25 06:08:45 +02:00
Version cgVersion = Assembly . GetEntryAssembly ( ) . GetName ( ) . Version ;
if ( asfVersion = = cgVersion ) {
2016-06-27 02:07:27 +02:00
return ;
}
2016-11-24 07:32:16 +01:00
Logging . LogGenericErrorWithoutStacktrace ( "Version of ASF and ConfigGenerator doesn't match!" + Environment . NewLine + "ASF version: " + asfVersion + " | ConfigGenerator version: " + cgVersion + Environment . NewLine + Environment . NewLine + "Please use ConfigGenerator from the same ASF release, I'll redirect you to appropriate ASF release..." ) ;
2016-06-27 02:07:27 +02:00
Process . Start ( "https://github.com/" + SharedInfo . GithubRepo + "/releases/tag/" + asfVersion ) ;
2016-05-13 06:32:42 +02:00
Environment . Exit ( 1 ) ;
2016-03-20 05:27:30 +01:00
}
2016-11-24 07:32:16 +01: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 ( ) ) ;
}
2016-03-20 05:27:30 +01:00
private static void UnhandledExceptionHandler ( object sender , UnhandledExceptionEventArgs args ) {
2016-07-25 06:08:45 +02:00
if ( args ? . ExceptionObject = = null ) {
Logging . LogNullError ( nameof ( args ) + " || " + nameof ( args . ExceptionObject ) ) ;
2016-03-20 05:27:30 +01:00
return ;
}
Logging . LogGenericException ( ( Exception ) args . ExceptionObject ) ;
}
private static void UnobservedTaskExceptionHandler ( object sender , UnobservedTaskExceptionEventArgs args ) {
2016-07-25 06:08:45 +02:00
if ( args ? . Exception = = null ) {
Logging . LogNullError ( nameof ( args ) + " || " + nameof ( args . Exception ) ) ;
2016-03-20 05:27:30 +01:00
return ;
}
Logging . LogGenericException ( args . Exception ) ;
}
}
2016-11-24 07:32:16 +01:00
}