예제 #1
0
    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;
            }
        }

        var  version = Environment.OSVersion.Version;
        bool canrun  = true;

        switch (version.Major)
        {
        case 5:
            canrun = false;
            break;

        case 6:
            switch (version.Minor)
            {
            case 0:
                canrun = false;
                break;
            }
            break;
        }
        if (!canrun)
        {
            MessageBox.Show("iSpy is not supported on this operating system. Please uninstall and download v6.5.8.0 instead. Your settings will be saved.");
            Process.Start("http://www.ispyconnect.com/download.aspx");
            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.LogException(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
                    MessageBox.Show("Another instance is running, application will exit", "iSpy");
                    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;


            _previousExecutionState = NativeCalls.SetThreadExecutionState(NativeCalls.EsContinuous | NativeCalls.EsSystemRequired);

            AppIdle = new WinFormsAppIdleHandler();
            var mf = new MainForm(silentstartup, command);
            GC.KeepAlive(FfmpegMutex);

            Application.Run(mf);
            FfmpegMutex.Close();

            ffmpeg.avformat_network_deinit();


            if (_previousExecutionState != 0)
            {
                NativeCalls.SetThreadExecutionState(_previousExecutionState);
            }
        }
        catch (Exception ex)
        {
            try
            {
                Logger.LogException(ex);
            } catch
            {
            }
            while (ex.InnerException != null)
            {
                try
                {
                    Logger.LogException(ex);
                }
                catch
                {
                }
                ex = ex.InnerException;
            }
        }
        try
        {
            Logger.WriteLogs();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
예제 #2
0
    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);
            }

            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
                {
                    for (int index = 0; index < args.Length; index++)
                    {
                        string s = args[index];
                        command += 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;

            FFMPEGMutex = new Mutex();

            Application.ThreadException += ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

            var ffmpegSetup = new Init();
            ffmpegSetup.Initialise();

            _previousExecutionState = NativeCalls.SetThreadExecutionState(NativeCalls.ES_CONTINUOUS | NativeCalls.ES_SYSTEM_REQUIRED);

            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
            {
                MainForm.LogExceptionToFile(ex);
            } catch
            {
            }
            while (ex.InnerException != null)
            {
                try
                {
                    MainForm.LogExceptionToFile(ex);
                }
                catch
                {
                }
            }
        }
    }