private static ProjectId ShowWelcomeDialog(FwAppArgs args, FwApp startingApp, ProjectId lastProjectId, StartupException exception) { CloseSplashScreen(); var helpTopicProvider = startingApp as IHelpTopicProvider; // Use the last edited project as the base guess for which project we'll open. var projectToTry = lastProjectId; // Continue to ask for an option until one is selected. s_fWaitingForUserOrOtherFw = true; do { if (exception != null) { if (projectToTry != null) Logger.WriteEvent("Problem opening " + projectToTry.UiName + "."); Logger.WriteError(exception); } // Put this here (i.e. inside the do loop) so any exceptions // will be logged before terminating. if (s_noUserInterface) return null; // If we changed our projectToTry below and we're coming through again, // reset our projectId. projectToTry = lastProjectId; using (WelcomeToFieldWorksDlg dlg = new WelcomeToFieldWorksDlg(helpTopicProvider, args.AppAbbrev, exception, s_noPreviousReportingSettings)) { if (exception != null) { dlg.ShowErrorLabelHideLink(); } else { if (projectToTry != null && projectToTry.IsValid) { dlg.ProjectLinkUiName = projectToTry.Name; dlg.SetFirstOrLastProjectText(false); } else { var sampleProjId = GetSampleProjectId(startingApp); if (sampleProjId != null) { dlg.ProjectLinkUiName = sampleProjId.Name; dlg.SetFirstOrLastProjectText(true); // LT-13943 - forgot to set this variable, which made it not be able to open // the sample db. projectToTry = new ProjectId(startingApp.SampleDatabase, null); } else // user didn't install Sena 3! { projectToTry = null; } } if (projectToTry != null) dlg.ShowLinkHideErrorLabel(); else dlg.ShowErrorLabelHideLink(); } bool gotAutoOpenSetting = false; if (startingApp.RegistrySettings != null) // may be null if disposed after canceled restore. { dlg.OpenLastProjectCheckboxIsChecked = GetAutoOpenRegistrySetting(startingApp); gotAutoOpenSetting = true; } dlg.StartPosition = FormStartPosition.CenterScreen; dlg.ShowDialog(); exception = null; // We get the app each time through the loop because a failed Restore operation can dispose it. var app = GetOrCreateApplication(args); if (gotAutoOpenSetting) app.RegistrySettings.AutoOpenLastEditedProject = dlg.OpenLastProjectCheckboxIsChecked; switch (dlg.DlgResult) { case WelcomeToFieldWorksDlg.ButtonPress.New: projectToTry = CreateNewProject(dlg, app, helpTopicProvider); Debug.Assert(projectToTry == null || projectToTry.IsValid); break; case WelcomeToFieldWorksDlg.ButtonPress.Open: projectToTry = ChooseLangProject(null, helpTopicProvider); try { if (projectToTry != null) projectToTry.AssertValid(); } catch (StartupException e) { exception = e; } break; case WelcomeToFieldWorksDlg.ButtonPress.Link: // LT-13943 - this guard keeps the projectToTry from getting blasted by a null when it has // a useful projectId (like the initial sample db the first time FLEx is run). if (lastProjectId != null && !lastProjectId.Equals(projectToTry)) projectToTry = lastProjectId; // just making sure! Debug.Assert(projectToTry.IsValid); break; case WelcomeToFieldWorksDlg.ButtonPress.Restore: s_allowFinalShutdown = false; RestoreProject(null, app); s_allowFinalShutdown = true; projectToTry = s_projectId; // Restore probably used this process break; case WelcomeToFieldWorksDlg.ButtonPress.Exit: return null; // Should cause the FW process to exit later case WelcomeToFieldWorksDlg.ButtonPress.Receive: if (!FwNewLangProject.CheckProjectDirectory(null, helpTopicProvider)) break; ObtainedProjectType obtainedProjectType; projectToTry = null; // If the user cancels the send/receive, this null will result in a return to the welcome dialog. // Hard to say what Form.ActiveForm is here. The splash and welcome dlgs are both gone. var projectDataPathname = ObtainProjectMethod.ObtainProjectFromAnySource(Form.ActiveForm, helpTopicProvider, out obtainedProjectType); if (!string.IsNullOrEmpty(projectDataPathname)) { projectToTry = new ProjectId(FDOBackendProviderType.kXML, projectDataPathname, null); var activeWindow = startingApp.ActiveMainWindow; if (activeWindow != null) { ((IFwMainWnd)activeWindow).Mediator.PropertyTable.SetProperty("LastBridgeUsed", obtainedProjectType == ObtainedProjectType.Lift ? "LiftBridge" : "FLExBridge", PropertyTable.SettingsGroup.LocalSettings); } } break; case WelcomeToFieldWorksDlg.ButtonPress.Import: projectToTry = CreateNewProject(dlg, app, helpTopicProvider); if (projectToTry != null) { var projectLaunched = LaunchProject(args, ref projectToTry); if (projectLaunched) { s_projectId = projectToTry; // Window is open on this project, we must not try to initialize it again. var mainWindow = Form.ActiveForm; if (mainWindow is IxWindow) { ((IxWindow) mainWindow).Mediator.SendMessage("SFMImport", null); } else { return null; } } else { return null; } } break; } } } while (projectToTry == null || !projectToTry.IsValid); Logger.WriteEvent("Project selected in Welcome dialog: " + projectToTry); s_fWaitingForUserOrOtherFw = false; return projectToTry; }