static void Main() { settings = new Settings(); settings.Load(); isp = new AbloadService(settings.Cookies); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (ProcessIcon pi = new ProcessIcon(settings, isp)) { kcm = new KeyControlManager(); selector = new Windows10RegionSelector(kcm.GlobalHook); ic = new NQuantImageCreator(); kcm.RegionShotStart = selector.Start; kcm.AbortRegionShot = selector.Abort; selector.RegionFinished += new EventHandler <RegionSelector.Region>( (sender, region) => { Stream image = ic.CreateFromScreenRegion(region); isp.Upload(image); } ); isp.UploadFinished += new EventHandler <UploadResult>( (sender, result) => { Clipboard.SetText(result.ImageUrl); pi.NotifyUser(Enum.GetName(typeof(UploadResult.UploadStatus), result.Status), result.ImageUrl, result.ImageUrl); } ); Application.Run(); } }
static void Main() { bool isAlreadyRunning = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Length > 1; if (isAlreadyRunning) { return; } #if !DEBUG try #endif { settings = new Config(); settings.Load(); isp = new AbloadService(settings.Cookies); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (ProcessIcon pi = new ProcessIcon(settings, isp)) { kcm = new KeyControlManager(); selector = new Windows10RegionSelector(kcm.GlobalHook); ic = new NQuantImageCreator(); // Tie display shot to key action kcm.DisplayShot = new Action(() => { Region region = selector.GetAllScreenRegion(); Stream image = ic.CreateFromScreenRegion(region); SaveAndUpload(image); }); // Tie single display shot to key action kcm.SingleDisplayShot = new Action(() => { Region region = selector.GetCurrentScreenRegion(); Stream image = ic.CreateFromScreenRegion(region); SaveAndUpload(image); }); // Tie window shot to key action kcm.WindowShot = new Action(() => { Region region = selector.GetCurrentWindowRegion(); Stream image = ic.CreateFromScreenRegion(region); SaveAndUpload(image); }); // Tie region selector to key events kcm.RegionShotStart = selector.Start; kcm.AbortRegionShot = selector.Abort; selector.RegionFinished += new EventHandler <Region>( (sender, region) => { Stream image = ic.CreateFromScreenRegion(region); SaveAndUpload(image); } ); isp.UploadFinished += new EventHandler <UploadResult>( (sender, result) => { if (result.Status == UploadResult.UploadStatus.Succeeded) { Clipboard.SetText(result.ImageUrl); pi.NotifyUserSuccess( Enum.GetName(typeof(UploadResult.UploadStatus), result.Status), result.ImageUrl, (string)result.Reason ); } else { var ex = result.Reason as Exception; pi.NotifyUserFail( Enum.GetName(typeof(UploadResult.UploadStatus), result.Status), ex.Message, ex.InnerException.Message ); } } ); Application.Run(); } } #if !DEBUG catch (Exception ex) { MessageBox.Show(null, ex.Message + "\r\n\r\nIf this is helpful for you, here is the stack trace:\r\n\r\n" + ex.GetType().ToString() + ex.StackTrace, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif }