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
                );
        }
        private static bool LaunchAction(string[] args, bool isFirstInstance)
        {
            if (isFirstInstance)
            {
                // Use GDI strings everywhere
                Application.SetCompatibleTextRenderingDefault(false);

                InitializeApplicationEnvironment();

                string downloadUrl = UpdateSettings.CheckForBetaUpdates ? UpdateSettings.BetaUpdateDownloadUrl : UpdateSettings.UpdateDownloadUrl;
                RegisterSquirrelEventHandlers(downloadUrl);

                try
                {
                    // TODO:OLW
                    // using (WindowsLiveSetup windowsLiveSetup = new WindowsLiveSetup())
                    // {
                    try
                    {
                        // TODO:OLW
                        // Load the culture.
                        LoadCulture("en");

                        // Apply any culture overrides.
                        WriterCommandLineOptions opts = WriterCommandLineOptions.Create(args);
                        if (!String.IsNullOrEmpty(opts.CultureOverride))
                        {
                            LoadCulture(opts.CultureOverride);
                        }

                        // Save the current culture for other instances.
                        currentUICulture = CultureInfo.CurrentUICulture;

                        // show splash screen
                        IDisposable splashScreen = null;
                        //	Show the splash screen.
                        SplashScreen splashScreenForm = new SplashScreen();
                        splashScreenForm.ShowSplashScreen();
                        splashScreen = new FormSplashScreen(splashScreenForm);

                        LaunchFirstInstance(splashScreen, args);
                    }
                    finally
                    {
                        // TODO:OLW
                        // windowsLiveSetup.ClearThreadUILanguages();
                    }
                    // }
                }
                catch (Exception)
                {
                    // Most likely we failed to create WLSetupClass, installation corrupt or incomplete
                    // Redirect user to repair/reinstall.
                    DisplayMessage.Show(MessageId.WriterCannotStart);
                }

                return(true);
            }
            else
            {
                return(LaunchAdditionalInstance(args));
            }
        }
Пример #3
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;
            }
        }