Esempio n. 1
0
 /// <summary>
 /// Handles the Click event of the Kill Background Processes control.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">
 /// The <see cref="System.EventArgs" /> instance containing the event data.
 /// </param>
 private static void ForceIPUpdate_Click(object sender, System.EventArgs e)
 {
     IPUpdater.CheckAndSendEmail(true);
 }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            // Quit if already running https://stackoverflow.com/a/6392264
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, ProductName);
            var runBenchmark             = false;
            var runHashTest = false;

            try
            {
                if (mutex.WaitOne(0, false))
                {
                    if (args != null && args.Length > 0)
                    {
                        for (var i = 0; i < args.Length; i++)
                        {
                            var s = args[i];
                            if (s == "--debug")
                            {
                                // Throw everything inside a new console window. This code works.
                                AllocConsole();
                                System.IntPtr stdHandle = GetStdHandle(StdOutputHandle);
                                Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = new Microsoft.Win32.SafeHandles.SafeFileHandle(stdHandle, true);
                                System.IO.FileStream   fileStream     = new System.IO.FileStream(safeFileHandle, System.IO.FileAccess.Write);
                                System.Text.Encoding   encoding       = System.Text.Encoding.GetEncoding(MyCodePage);
                                System.IO.StreamWriter standardOutput = new System.IO.StreamWriter(fileStream, encoding)
                                {
                                    AutoFlush = true
                                };
                                System.Console.SetOut(standardOutput);
                            }
                            if (s == "--benchmark")
                            {
                                runBenchmark = true;
                            }
                            if (s == "--test")
                            {
                                runHashTest = true;
                            }
                        }
                    }
                    if (!runBenchmark)
                    {
                        // Show the system tray icon.
                        System.Windows.Forms.Application.EnableVisualStyles();

                        System.Timers.Timer aTimer = new System.Timers.Timer();
                        aTimer.Elapsed += OnTimedEvent;
                        aTimer.Interval = 1000 * 7200; // 120 minutes
                        aTimer.Enabled  = true;

                        // Put the icon in the system tray
                        STrayIcon.Icon    = Properties.Resources.HatSync;
                        STrayIcon.Text    = "HatSync";
                        STrayIcon.Visible = true;

                        // Run once at startup
                        IPUpdater.Init();

                        // Attach a context menu.
                        MenuGenerator.RegenerateMenu();

                        if (runHashTest)
                        {
                            //==============================================================
                            // TEST Hash a file. The value should always be the same
                            // otherwise something went wrong with the implementation.

                            // Create dummy file
                            const string data = "Hello, world!";
                            const string name = "test.bin";
                            System.IO.File.WriteAllText(name, data);
                            // Hash it
                            UniqueFile result = new UniqueFile(name);
                            Log.WriteLine("Hash of test file: " + result.GetHashAsString());

                            if (result.GetHashAsString() == "B5DA441CFE72AE042EF4D2B17742907F675DE4DA57462D4C3609C2E2ED755970")
                            {
                                Log.WriteLine("Test Sucessful");
                            }
                            else
                            {
                                Log.WriteLine("Shit.");
                            }

                            if (System.IO.File.Exists(name))
                            {
                                System.IO.File.Delete(name);
                            }
                        }

                        System.Windows.Forms.Application.Run();
                    }
#if USE_BENCHMARKDOTNET
                    else
                    {
                        BenchmarkDotNet.Running.BenchmarkRunner.Run <Md5VsSha256VsBlake2>();
                    }
#endif
                }
            }
            finally
            {
                mutex.Close();
                mutex = null;
            }
        }