コード例 #1
0
ファイル: Form1.cs プロジェクト: bexamous/EasyImgur
        public Form1(SingleInstance _SingleInstance, string[] _Args)
        {
            InitializeComponent();

            ImplementPortableMode();

            CreateHandle(); // force the handle to be created so Invoke succeeds; see issue #8 for more detail

            this.notifyIcon1.ContextMenu = this.trayMenu;

            this.versionLabel.Text = "Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            Application.ApplicationExit += new System.EventHandler(this.ApplicationExit);

            InitializeEventHandlers();
            History.BindData(historyItemBindingSource); // to use the designer with data binding, we have to pass History our BindingSource, instead of just getting one from History
            History.InitializeFromDisk();

            // if we have arguments, we're going to show a tip when we handle those arguments.
            if(_Args.Length == 0)
                ShowBalloonTip(2000, "EasyImgur is ready for use!", "Right-click EasyImgur's icon in the tray to use it!", ToolTipIcon.Info);

            ImgurAPI.AttemptRefreshTokensFromDisk();

            Statistics.GatherAndSend();

            _SingleInstance.ArgumentsReceived += singleInstance_ArgumentsReceived;
            if(_Args.Length > 0) // handle initial arguments
                singleInstance_ArgumentsReceived(this, new ArgumentsReceivedEventArgs() { Args = _Args });
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var guid = new Guid("{75da63f2-9b76-4590-82b3-b8a108e53cf0}");

            using (var singleInstance = new SingleInstance(guid))
            {
                if (singleInstance.IsFirstInstance)
                {
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EasyImgur"))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EasyImgur");
                    }

                    singleInstance.ListenForArgumentsFromSuccessiveInstances();

                    AppDomain.CurrentDomain.AssemblyResolve += FindDll;

                    foreach (string arg in args.Where(s => s != null))
                    {
                        if (arg == "/portable")
                        {
                            MakeSettingsPortable(Properties.Settings.Default);
                            _isInPortableMode = true;
                            Log.Info("Started in portable mode.");
                        }
                    }

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    var form = new Form1(singleInstance, args);
                    Properties.Settings.Default.Reload(); // To make sure we can access the current settings.

#if DEBUG                                                 // We want VS to get the source of the exception instead of coming to this throw when debugging
                    Application.Run();                    // Don't put the new form instance here m'kay
#else
                    try
                    {
                        Application.Run();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Fatal exception in main thread: " + ex.ToString());
                        throw; // crash and burn; I'm not sure it's safe to show a message box so just crash
                    }
#endif
                }
                else
                {
                    singleInstance.PassArgumentsToFirstInstance(args);
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bexamous/EasyImgur
        static void Main(string[] args)
        {
            var guid = new Guid("{75da63f2-9b76-4590-82b3-b8a108e53cf0}");
            using (var singleInstance = new SingleInstance(guid))
            {
                if (singleInstance.IsFirstInstance)
                {
                    if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EasyImgur"))
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EasyImgur");

                    singleInstance.ListenForArgumentsFromSuccessiveInstances();

                    AppDomain.CurrentDomain.AssemblyResolve += FindDll;

                    foreach (string arg in args.Where(s => s != null))
                    {
                        if (arg == "/portable")
                        {
                            MakeSettingsPortable(Properties.Settings.Default);
                            _isInPortableMode = true;
                            Log.Info("Started in portable mode.");
                        }
                    }

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    var form = new Form1(singleInstance, args);
                    Properties.Settings.Default.Reload();   // To make sure we can access the current settings.

            #if DEBUG           // We want VS to get the source of the exception instead of coming to this throw when debugging
                    Application.Run(); // Don't put the new form instance here m'kay
            #else
                    try
                    {
                        Application.Run();
                    }
                    catch(Exception ex)
                    {
                        Log.Error("Fatal exception in main thread: " + ex.ToString());
                        throw; // crash and burn; I'm not sure it's safe to show a message box so just crash
                    }
            #endif
                }
                else
                    singleInstance.PassArgumentsToFirstInstance(args);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Cologler/EasyImgur
        private static void Entry(SingleInstance singleInstance, string[] args)
        {
            #if DEBUG
            try
            {
            #endif
                using (var app = new EasyImgurApplication())
                {
                    AppDomain.CurrentDomain.AssemblyResolve += FindDll;
                    const string portableFlag = "portable";
                    if (args.Any(arg => arg == "/" + portableFlag) || File.Exists(portableFlag))
                    {
                        if (!File.Exists(portableFlag)) using (File.Open(portableFlag, FileMode.OpenOrCreate)) { }
                        isInPortableMode = true;
                    }

                    if (isInPortableMode)
                    {
                        MakeSettingsPortable(Settings.Default);
                        Log.Info("Started in portable mode.");
                    }
                    else
                    {
                        var folder = RootFolder;
                        if (!Directory.Exists(folder))
                            Directory.CreateDirectory(folder);
                    }

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    var form = new Form1(singleInstance, args);
                    Settings.Default.Reload();

                    app.Initialize();
                    Application.Run();
                }
            #if DEBUG
            }
            catch (Exception ex)
            {
                Log.Error("Fatal exception in main thread: " + ex.ToString());
                throw; // crash and burn; I'm not sure it's safe to show a message box so just crash
            }
            #endif
        }
コード例 #5
0
        public Form1(SingleInstance _SingleInstance, string[] _Args)
        {
            InitializeComponent();

            ImplementPortableMode();

            CreateHandle(); // force the handle to be created so Invoke succeeds; see issue #8 for more detail

            this.notifyIcon1.ContextMenu = this.trayMenu;

            this.versionLabel.Text = "Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            Application.ApplicationExit += new System.EventHandler(this.ApplicationExit);

            InitializeEventHandlers();
            History.BindData(historyItemBindingSource); // to use the designer with data binding, we have to pass History our BindingSource, instead of just getting one from History
            History.InitializeFromDisk();

            // if we have arguments, we're going to show a tip when we handle those arguments.
            if (_Args.Length == 0)
            {
                ShowBalloonTip(2000, "EasyImgur is ready for use!", "Right-click EasyImgur's icon in the tray to use it!", ToolTipIcon.Info);
            }

            ImgurAPI.AttemptRefreshTokensFromDisk();

            Statistics.GatherAndSend();

            _SingleInstance.ArgumentsReceived += singleInstance_ArgumentsReceived;
            if (_Args.Length > 0) // handle initial arguments
            {
                singleInstance_ArgumentsReceived(this, new ArgumentsReceivedEventArgs()
                {
                    Args = _Args
                });
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Cologler/EasyImgur
 static void Main(string[] args)
 {
     var guid = new Guid("{75da63f2-9b76-4590-82b3-b8a108e53cf0}");
     using (var singleInstance = new SingleInstance(guid))
     {
         if (singleInstance.IsFirstInstance)
         {
             singleInstance.ListenForArgumentsFromSuccessiveInstances();
             Entry(singleInstance, args);
         }
         else
             singleInstance.PassArgumentsToFirstInstance(args);
     }
 }