public static void Initialise(bool optimise = true) { Optimise = optimise; // Our executabe needs to know how to find the native libraries // For Windows, we can set this to be x86 or x64 directory at runtime (below) // For Linux we need to move our native libraries to 'netcoredeps' which is set by .net core // For OSX we need to set an environment variable (DYLD_LIBRARY_PATH) outside of the process by a script if (Environment.OSVersion.Platform == PlatformID.Win32NT) { try { SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); AddDllDirectory(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86" )); } catch { // Pre-Windows 7, KB2533623 SetDllDirectory(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86" )); } } // .NET Core also doesn't use DllImport but we can replicate this using NativeLibrary as per below // Uses FNA.dll.config to dictate what the name of the native library is per platform and architecture var fnaAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels)); DllMap.Register(fnaAssembly); }
static void Main(string[] args) { #if NETCOREAPP DllMap.Initialise(false); #endif // https://github.com/FNA-XNA/FNA/wiki/4:-FNA-and-Windows-API#64-bit-support if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetDllDirectory(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86" )); } // https://github.com/FNA-XNA/FNA/wiki/7:-FNA-Environment-Variables#fna_graphics_enable_highdpi // NOTE: from documentation: // Lastly, when packaging for macOS, be sure this is in your app bundle's Info.plist: // <key>NSHighResolutionCapable</key> // <string>True</string> Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "1"); using (AnathemaGame game = new AnathemaGame()) { bool isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1"; if (isHighDPI) { Debug.WriteLine("HiDPI Enabled"); } game.Run(); } }
public static void Initialise(bool optimise = true) { Optimise = optimise; // Our executabe needs to know how to find the native libraries // For Windows, we can set this to be x86 or x64 directory at runtime (below) // For Linux we need to move our native libraries to 'netcoredeps' which is set by .net core // For OSX we need to set an environment variable (DYLD_LIBRARY_PATH) outside of the process by a script if (Environment.OSVersion.Platform == PlatformID.Win32NT) { try { SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); AddDllDirectory(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86" )); } catch { // Pre-Windows 7, KB2533623 SetDllDirectory(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Environment.Is64BitProcess ? "x64" : "x86" )); } } // .NET Core also doesn't use DllImport but we can replicate this using NativeLibrary as per below // Uses FNA.dll.config to dictate what the name of the native library is per platform and architecture var fnaAssembly = Assembly.GetAssembly(typeof(Microsoft.Xna.Framework.Graphics.ColorWriteChannels)); DllMap.Register(fnaAssembly); // OTHER STUFF // Required to allow window to be resized - must be set before XAGE engine started Environment.SetEnvironmentVariable("FNA_WORKAROUND_WINDOW_RESIZABLE", "1"); Environment.SetEnvironmentVariable("FNA_WORKAROUND_WINDOW_COLOR", 0x000000.ToString()); // Invoke some activities asynchronously to reduce the startup time if (Optimise) { Task.Run(() => WarmupFAudio()); } // Make console a decent size try { if (Console.WindowWidth > 0) { Console.SetWindowSize(140, 35); } } catch (IOException) // Swallow exception - cannot be done if project OutputType is 'Windows Application', not sure how to detect this { } }
public void GetAnomalies() { string dllPath; DllMap.TryGetValue(CurrentDetector, out dllPath); bool madeReport = Program.OperateDLL(dllPath); if (madeReport) { IsDetectorOn = true; } }
public static void Main() { try { DllMap.Register(Assembly.GetExecutingAssembly()); int thirty = NativeSum(10, 20); Console.WriteLine($"OldLib.NativeSum(10,20) = {thirty}"); } catch (Exception e) { Console.WriteLine($"Error: {e.Message} Line: {e.Source}"); } }
public static int Main() { try { DllMap.Register(Assembly.GetExecutingAssembly()); int thirty = NativeSum(10, 20); if (thirty != 30) { Console.WriteLine("Wrong result from native call"); return(101); } } catch (Exception e) { Console.WriteLine("Unexpected exception: {0}", e.Message); return(102); } return(100); }
/// <summary> /// The main entry point for the application. This instantiates and runs our game (within XAGE.Engine.Core.dll) /// </summary> static void Main(string[] args) { // Settings that get injected into the engine RunSettings runSettings = new RunSettings ( release: Release, allowDebugging: AllowDebugging, logLevel: LogLevel, logAsync: LogAsync, onNotImplemented: OnNotImplemented, catchScriptExceptions: CatchScriptExceptions, loader: Awakener.CSharpScript.Load, serializer: Awakener.CSharpScript.Serialize, deserializer: Awakener.CSharpScript.Deserialize, type: typeof(Awakener.CSharpScript) ); // Initialise DLL mapping and other pre-game items DllMap.Initialise(); // Run the game - any unhandled exceptions will be caught in Release mode only // In Debug mode it will stop in place, which is generally more useful for debugging try { using (XNAGame game = new XNAGame(runSettings)) { game.Run(); } } catch (Exception exc) when(CatchEngineExceptions) { Logger.Fatal("Unhandled exception: " + exc.Message); Logger.Fatal("StackTrace: " + exc.StackTrace); } finally { Logger.Reset(); } }
/// <summary> /// The main entry point for the application. This instantiates and runs our game (within XAGE.Engine.Core.dll) /// </summary> static void Main(string[] args) { // Must do this before anything else DllMap.Initialise(); // Create Script Delegates that get injected into the engine RunSettings runSettings = new RunSettings( Release, AllowDebugging, LogLevel, LogAsync, OnNotImplemented, LastnFurious.CSharpScript.Load, LastnFurious.CSharpScript.Serialize, LastnFurious.CSharpScript.Deserialize, typeof(LastnFurious.CSharpScript)); // Run the game - any unhandled exceptions will be caught in Release mode only // In Debug mode it will stop in place, which is generally more useful for debugging try { using (XNAGame game = new XNAGame(runSettings)) { game.Run(); } } catch (Exception exc) when(CatchFatalExceptions) { Logger.Fatal("Unhandled exception: " + exc.Message); Logger.Fatal("StackTrace: " + exc.StackTrace); } finally { Logger.Reset(); } }
static int Main(string[] args) { DllMap.Register(Assembly.GetAssembly(typeof(Pkcs11Uri))); CommandLineOptions options; try { options = CommandLineParser.Parse(args); _serviceProvider = Startup.Configure(options.LogFilePath, options.NativeLibraryPath); } catch (AppMustBeClosedException ex) { return(ex.RetCode); } var core = _serviceProvider.GetService <TokenSlot>(); var pinsStore = _serviceProvider.GetService <PinsStorage>(); var configLinesStore = _serviceProvider.GetService <ConfigLinesStorage>(); var logMessageBuilder = _serviceProvider.GetService <LogMessageBuilder>(); try { if (!string.IsNullOrWhiteSpace(options.PinFilePath)) { pinsStore.Load(options.PinFilePath); } if (!string.IsNullOrWhiteSpace(options.ConfigurationFilePath)) { configLinesStore.Load(options.ConfigurationFilePath); return(Main(configLinesStore.GetNext().Trim().Split(" "))); } var initialSlots = core.GetInitialSlots(); if (!initialSlots.Any()) { Console.WriteLine(Resources.WaitingNextToken); } while (true) { if (!initialSlots.TryPop(out var slot)) { var cts = new CancellationTokenSource(); var token = cts.Token; var waitTokenTask = Task.Run(() => { try { slot = core.WaitToken(); } catch (Pkcs11Exception e) when(e.RV == CKR.CKR_CRYPTOKI_NOT_INITIALIZED) { } finally { cts.Cancel(); } }); var waitExitKeyTask = Task.Run(() => { while (Console.KeyAvailable) { Console.ReadKey(true); } while (Console.ReadKey(true).Key != ConsoleKey.Q && !token.IsCancellationRequested) { ; } }); var completedTask = Task.WhenAny(waitTokenTask, waitExitKeyTask).Result; if (completedTask == waitExitKeyTask && !token.IsCancellationRequested) { throw new AppMustBeClosedException(0); } } if (options.SerialNumber != null && !string.Equals(slot.GetTokenInfo().SerialNumber, options.SerialNumber, StringComparison.OrdinalIgnoreCase)) { continue; } var commandHandlerBuilder = _serviceProvider.GetService <CommandHandlerBuilder>() .ConfigureWith(slot, options); foreach (var(key, value) in _optionsMapping) { if (key.Invoke(options)) { value.Invoke(commandHandlerBuilder); } } try { commandHandlerBuilder.Execute(); } catch (TokenMustBeChangedException) { // ignored (перейти к следующему токену) } if (options.OneIterationOnly) { break; } Console.WriteLine(Resources.WaitingNextToken); } _retCode = (int)CKR.CKR_OK; } catch (Pkcs11Exception ex) { Console.Error.WriteLine(logMessageBuilder.WithPKCS11Error(ex.RV)); _retCode = (int)ex.RV; } catch (CKRException ex) { Console.Error.WriteLine(ex.Message); _retCode = (int)ex.ReturnCode; } catch (AppMustBeClosedException ex) { return(ex.RetCode); } catch (Exception ex) { Console.Error.WriteLine(logMessageBuilder.WithUnhandledError(ex.Message)); _retCode = -1; } finally { DisposeServices(); } return(_retCode); }