Init.Initialise C# (CSharp) Method

Initialise() private method

private Initialise ( ) : void
return void
    public static void Initialise()
    {
        TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast();
    }
}

Usage Example

示例#1
0
文件: Program.cs 项目: tdhieu/iSpy
    private static void Main(string[] args)
    {
        //uninstall?
        string[] arguments = Environment.GetCommandLineArgs();

        foreach (string argument in arguments)
        {
            if (argument.Split('=')[0].ToLower() == "/u")
            {
                string guid = argument.Split('=')[1];
                string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
                var si = new ProcessStartInfo(path + "/msiexec.exe", "/x " + guid);
                Process.Start(si);
                Application.Exit();
                return;
            }
        }

        try
        {
            Application.EnableVisualStyles();            
            Application.SetCompatibleTextRenderingDefault(false);


            bool firstInstance = true;

            var me = Process.GetCurrentProcess();
            var arrProcesses = Process.GetProcessesByName(me.ProcessName);

            //only want to do this if not passing in a command

            if (arrProcesses.Length > 1)
            {
                firstInstance = false;
            }
            
            string executableName = Application.ExecutablePath;
            var executableFileInfo = new FileInfo(executableName);
            ExecutableDirectory = executableFileInfo.DirectoryName;

            bool ei = (!Directory.Exists(AppDataPath) || !Directory.Exists(AppDataPath + @"XML\") ||
                       !File.Exists(AppDataPath + @"XML\config.xml"));
            if (ei)
                EnsureInstall(true);
            else
            {
                try
                {
                    var o = Registry.CurrentUser.OpenSubKey(@"Software\ispy",true);
                    if (o?.GetValue("firstrun") != null)
                    {
                        o.DeleteValue("firstrun");
                        //copy over updated static files on first run of new install
                        EnsureInstall(false);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogExceptionToFile(ex, "startup");
                }
            }

            bool silentstartup = false;

            string command = "";
            if (args.Length > 0)
            {
                if (args[0].ToLower().Trim() == " - reset" && !ei)
                {
                    if (firstInstance)
                    {
                        if (
                            MessageBox.Show("Reset iSpy? This will overwrite all your settings.", "Confirm",
                                            MessageBoxButtons.OKCancel) == DialogResult.OK)
                            EnsureInstall(true);
                    }
                    else
                    {
                        MessageBox.Show("Please exit iSpy before resetting it.");
                    }
                }
                if (args[0].ToLower().Trim() == "-silent" || args[0].ToLower().Trim('\\') == "s")
                {
                    if (firstInstance)
                    {
                        silentstartup = true;
                    }
                }
                else
                {
                    command = args.Aggregate(command, (current, s) => current + (s + " "));
                }
            }

            if (!firstInstance)
            {
                if (!string.IsNullOrEmpty(command))
                {
                    File.WriteAllText(AppDataPath + "external_command.txt", command);
                    Thread.Sleep(1000);
                }
                else
                {
                    //show form
                    File.WriteAllText(AppDataPath + "external_command.txt", "showform");
                    Thread.Sleep(1000);
                }
                
                Application.Exit();
                return;
            }

            if (IntPtr.Size == 8)
                Platform = "x64";

            File.WriteAllText(AppDataPath + "external_command.txt", "");

            // in case our https certificate ever expires or there is some other issue
            ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.DefaultConnectionLimit = 1000;

            FfmpegMutex = new Mutex();
            
            Application.ThreadException += ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
            
            var ffmpegSetup = new Init();
            ffmpegSetup.Initialise();

            _previousExecutionState = NativeCalls.SetThreadExecutionState(NativeCalls.EsContinuous | NativeCalls.EsSystemRequired);
            
            AppIdle = new WinFormsAppIdleHandler {Enabled = false};
            var mf = new MainForm(silentstartup, command);
            Application.Run(mf);
            FfmpegMutex.Close();

            GC.KeepAlive(FfmpegMutex);
            AppIdle.Enabled = false;
            ffmpegSetup.DeInitialise();
            

            if (_previousExecutionState != 0)
            {
                NativeCalls.SetThreadExecutionState(_previousExecutionState);
            }
            
        }
        catch (Exception ex)
        {
            try
            {
                Logger.LogExceptionToFile(ex);
            } catch
            {
                
            }
            while (ex.InnerException != null)
            {
                try
                {
                    Logger.LogExceptionToFile(ex);
                }
                catch
                {

                }
            }
        }
    }
All Usage Examples Of Init::Initialise