예제 #1
0
            public void OpenForm()
            {
                // open a new form on a non-background, STA thread

                using (ProcessKeepalive.Open()) // throws exception if we are shutting down
                {
                    // this object will be signalled when the new thread has
                    // finished incrementing
                    object signalIncremented = new object();

                    Thread formThread = ThreadHelper.NewThread(
                        ThreadStartWithParams.Create(new ThreadStartWithParamsDelegate(ThreadMain), signalIncremented),
                        "FormThread",
                        true,
                        true,
                        false);

                    lock (signalIncremented)
                    {
                        formThread.Start();
                        // Don't continue until refcount has been incremented
                        Monitor.Wait(signalIncremented);
                    }
                }
            }
        public static void Main(string[] args)
        {
            // WinLive 281407: Remove the current working directory from the dll search path
            // This prevents a rogue dll (wlidcli.dll) from being loaded while doing
            // something like opening a .wpost from a network location.
            Kernel32.SetDllDirectory("");

            // Enable custom visual styles for Writer.
            Application.EnableVisualStyles();

            // OLW doesn't work well at all from the guest account, so just block that
            // There is no protection from asserts here, so DON'T ASSERT
            WindowsIdentity currentUser = WindowsIdentity.GetCurrent();

            if (currentUser.User.IsWellKnown(WellKnownSidType.AccountGuestSid))
            {
                DisplayMessage.Show(MessageId.GuestNotSupported);
                return;
            }

            // add Plugins directory to probing path
            AppDomain currentDomain = AppDomain.CurrentDomain;

            ProcessKeepalive.SetFactory(ManualKeepalive.Factory);

            WriterCommandLineOptions opts = WriterCommandLineOptions.Create(args);

            if (opts == null)
            {
                return;
            }
            opts.ApplyOptions();

            // Make the appId unique by base directory and locale.
            // This might allow for easier testing of English vs. loc builds.
            string appId = "OpenLiveWriterApplication";

            try
            {
                appId = string.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}",
                                      "OpenLiveWriterApplication",
                                      currentDomain.BaseDirectory.GetHashCode(),
                                      CultureInfo.CurrentUICulture,
                                      Res.DebugMode ? ".locspy" : "");
            }
            catch (Exception e)
            {
                Debug.Fail(e.ToString());
            }

            //initialize the default internet features for browser controls
            InitInternetFeatures();

            SingleInstanceApplicationManager.Run(
                appId,
                LaunchAction,
                args
                );
        }
예제 #3
0
        private void Main()
        {
            try
            {
                // delay the check for updates
                Thread.Sleep(1000);

                // only run one service-update at a time process wide
                lock (_serviceUpdateLock)
                {
                    // establish settings detection context
                    ServiceUpdateSettingsDetectionContext settingsDetectionContext = new ServiceUpdateSettingsDetectionContext(_blogId);

                    // fire-up a blog settings detector to query for changes
                    BlogSettingsDetector settingsDetector = new BlogSettingsDetector(settingsDetectionContext);
                    settingsDetector.SilentMode = true;
                    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(ApplicationEnvironment.SettingsRootKeyName + @"\Weblogs\" + _blogId + @"\HomepageOptions"))
                    {
                        if (key != null)
                        {
                            settingsDetector.IncludeFavIcon            = false;
                            settingsDetector.IncludeCategories         = settingsDetectionContext.BlogSupportsCategories;
                            settingsDetector.UseManifestCache          = true;
                            settingsDetector.IncludeHomePageSettings   = false;
                            settingsDetector.IncludeCategoryScheme     = false;
                            settingsDetector.IncludeInsecureOperations = false;
                        }
                    }
                    settingsDetector.IncludeImageEndpoints = false;
                    settingsDetector.DetectSettings(SilentProgressHost.Instance);

                    // write the settings
                    using (ProcessKeepalive.Open())
                    {
                        using (BlogSettings settings = BlogSettings.ForBlogId(_blogId))
                            settings.ApplyUpdates(settingsDetectionContext);
                    }

                    // if changes were made then fire an event to notify the UI
                    if (settingsDetectionContext.HasUpdates)
                    {
                        _settingsChangedHandler(_blogId, false);
                    }
                }
            }
            catch (ManualKeepaliveOperationException)
            {
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception during ServiceUpdateChecker.Main: " + ex.ToString());
            }
        }
예제 #4
0
            private void ThreadMain(object[] parameters)
            {
                IDisposable splashScreen = null;

                if (parameters.Length > 0)
                {
                    splashScreen = parameters[parameters.Length - 1] as IDisposable;
                }

                ProcessKeepalive pk = null;

                try
                {
                    try
                    {
                        pk = ProcessKeepalive.Open();
                    }
                    finally
                    {
                        object signalIncremented = parameters[0];
                        lock (signalIncremented)
                            Monitor.Pulse(parameters[0]);
                    }

                    // housekeeping initialization
                    Application.OleRequired();
                    UnexpectedErrorDelegate.RegisterWindowsHandler();

                    // Create and run the form
                    SatelliteApplicationForm applicationForm = (SatelliteApplicationForm)Activator.CreateInstance(_formType, _parameters);
                    Application.Run(applicationForm);
                }
                catch (Exception ex)
                {
                    UnexpectedErrorMessage.Show(ex);
                }
                finally
                {
                    if (pk != null)
                    {
                        pk.Dispose();
                    }
                    if (splashScreen != null)
                    {
                        Debug.Assert(splashScreen is FormSplashScreen);
                        splashScreen.Dispose();
                    }
                }
            }
예제 #5
0
        public static void LaunchBloggingForm(string[] args, IDisposable splashScreen, bool isFirstInstance)
        {
            try
            {
                using (ProcessKeepalive.Open())
                {
                    UpdateManager.CheckforUpdates();

                    // If the COM registration is not set up correctly, we won't be able to launch.
                    RunningObjectTable.EnsureComRegistration();

                    // make sure blogging is configured before we proceed
                    if (EnsureBloggingConfigured(splashScreen))
                    {
                        WriterCommandLineOptions options = WriterCommandLineOptions.Create(args);

                        // check for a prefs request
                        if (options.IsShowPreferences)
                        {
                            if (splashScreen != null)
                            {
                                splashScreen.Dispose();
                            }

                            ExecuteShowPreferences(options.PreferencesPage);
                        }

                        // check for an open-post request
                        else if (options.IsOpenPost)
                        {
                            if (splashScreen != null)
                            {
                                splashScreen.Dispose();
                            }

                            ExecuteOpenPost();
                        }

                        // check for opening an existing post via the shell file association
                        else if (options.IsPostEditorFile)
                        {
                            ExecutePostEditorFile(options.PostEditorFileName, splashScreen);
                        }

                        // check for recovered posts
                        else if (isFirstInstance && RecoverPosts(splashScreen))
                        {
                            return;
                        }

                        // launch with an new empty post
                        else
                        {
                            ExecuteNewPost(splashScreen, null);
                        }
                    }
                }
            }
            catch
            {
                if (splashScreen != null)
                {
                    splashScreen.Dispose();
                }
                throw;
            }
        }