static int Main(string[] args1)
{
Logger.Init();
CheckForCorruptUserConfig();
// Bloom has several command line scenarios, without a coherent system for them.
// The following is how we will do things from now on, and things can be moved
// into this as time allows. See CommandLineOptions.cs.
if (args1.Length > 0 && new[] {"--help", "hydrate", "download", "getfonts"}.Contains(args1[0])) //restrict using the commandline parser to cases were it should work
{
#if !__MonoCS__
AttachConsole(-1);
#endif
var exitCode = CommandLine.Parser.Default.ParseArguments(args1,
new[] {typeof (HydrateParameters), typeof (DownloadBookOptions), typeof (GetUsedFontsParameters)})
.MapResult(
(HydrateParameters opts) => HandlePrepareCommandLine(opts),
(DownloadBookOptions opts) => DownloadBookCommand.HandleSilentDownload(opts),
(GetUsedFontsParameters opts) => GetUsedFontsCommand.Handle(opts),
errors =>
{
var code = 0;
foreach(var error in errors)
{
if(!(error is HelpVerbRequestedError))
{
Debug.WriteLine(error.ToString());
Console.WriteLine(error.ToString());
code = 1;
}
}
return code;
});
return exitCode; // we're done
}
//Debug.Fail("Attach Now");
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
XWebBrowser.DefaultBrowserType = XWebBrowser.BrowserType.GeckoFx;
var args = args1;
if (SIL.PlatformUtilities.Platform.IsWindows)
{
OldVersionCheck();
}
//bring in settings from any previous version
if (Settings.Default.NeedUpgrade)
{
//see http://stackoverflow.com/questions/3498561/net-applicationsettingsbase-should-i-call-upgrade-every-time-i-load
Settings.Default.Upgrade();
Settings.Default.Reload();
Settings.Default.NeedUpgrade = false;
Settings.Default.MaximizeWindow = true; // this is needed to force this to be written to the file, where a user can find it to modify it by hand (our video maker)
Settings.Default.Save();
StartUpWithFirstOrNewVersionBehavior = true;
}
if (IsInstallerLaunch(args))
{
InstallerSupport.HandleSquirrelInstallEvent(args); // may exit program
}
// Needs to be AFTER HandleSquirrelInstallEvent, because that can happen when the program is launched by Update rather than
// by the user.
if (!Settings.Default.LicenseAccepted)
{
Browser.SetUpXulRunner();
using (var dlg = new LicenseDialog())
if (dlg.ShowDialog() != DialogResult.OK)
return 1;
Settings.Default.LicenseAccepted = true;
Settings.Default.Save();
}
#if !USING_CHORUS
Settings.Default.ShowSendReceive = false; // in case someone turned it on before we disabled
#endif
#if DEBUG
if (args.Length > 0)
{
// This allows us to debug things like interpreting a URL.
MessageBox.Show("Attach debugger now");
}
#endif
// Ensures that registration settings for all channels of Bloom are stored in a common place,
// so the user is not asked to register each independently.
RegistrationSettingsProvider.SetProductName("Bloom");
Dictionary<string, string> propertiesThatGoWithEveryEvent = ErrorReport.GetStandardProperties();
propertiesThatGoWithEveryEvent.Remove("MachineName");
propertiesThatGoWithEveryEvent.Remove("UserName");
propertiesThatGoWithEveryEvent.Remove("UserDomainName");
propertiesThatGoWithEveryEvent.Add("channel", ApplicationUpdateSupport.ChannelName);
#if DEBUG
using(
new DesktopAnalytics.Analytics("sje2fq26wnnk8c2kzflf", RegistrationDialog.GetAnalyticsUserInfo(),
propertiesThatGoWithEveryEvent, false))
_supressRegistrationDialog = true;
#else
string feedbackSetting = System.Environment.GetEnvironmentVariable("FEEDBACK");
//default is to allow tracking
var allowTracking = string.IsNullOrEmpty(feedbackSetting) || feedbackSetting.ToLowerInvariant() == "yes"
|| feedbackSetting.ToLowerInvariant() == "true";
_supressRegistrationDialog = _supressRegistrationDialog || !allowTracking;
using (new DesktopAnalytics.Analytics("c8ndqrrl7f0twbf2s6cv", RegistrationDialog.GetAnalyticsUserInfo(), propertiesThatGoWithEveryEvent, allowTracking))
#endif
{
// do not show the registration dialog if bloom was started for a special purpose
if (args.Length > 0)
_supressRegistrationDialog = true;
if (args.Length == 1 && args[0].ToLowerInvariant().EndsWith(".bloompack"))
{
SetUpErrorHandling();
using (_applicationContainer = new ApplicationContainer())
{
SetUpLocalization();
var path = args[0];
// This allows local links to bloom packs.
if (path.ToLowerInvariant().StartsWith("bloom://"))
{
path = path.Substring("bloom://".Length);
if (!RobustFile.Exists(path))
{
path = FileLocator.GetFileDistributedWithApplication(true, path);
if (!RobustFile.Exists(path))
return 1;
}
}
using (var dlg = new BloomPackInstallDialog(path))
{
dlg.ShowDialog();
if (dlg.ExitWithoutRunningBloom)
return 1;
}
}
}
if (IsBloomBookOrder(args))
{
HandleDownload(args[0]);
// If another instance is running, this one has served its purpose and can exit right away. Otherwise,
// carry on with starting up normally. See https://silbloom.myjetbrains.com/youtrack/issue/BL-3822.
if (!UniqueToken.AcquireTokenQuietly(_mutexId))
return 0;
}
else
{
// Check whether another instance of Bloom is running. That should happen only when downloading a book because
// BloomLibrary starts a new Bloom process even when one is already running. But that is taken care of in the
// other branch of this if/else. So quit if we find another instance of Bloom running at this point.
// (A message will pop up to tell the user about this situation if it happens.)
if (!UniqueToken.AcquireToken(_mutexId, "Bloom"))
return 1;
}
OldVersionCheck();
SetUpErrorHandling();
using (_applicationContainer = new ApplicationContainer())
{
if (args.Length == 2 && args[0].ToLowerInvariant() == "--upload")
{
// A special path to upload chunks of stuff. This is not currently documented and is not very robust.
// - User must log in before running this
// - For best results each bloom book needs to be part of a collection in its parent folder
// - little error checking (e.g., we don't apply the usual constraints that a book must have title and licence info)
SetUpLocalization();
Browser.SetUpXulRunner();
Browser.XulRunnerShutdown += OnXulRunnerShutdown;
var transfer = new BookTransfer(new BloomParseClient(), ProjectContext.CreateBloomS3Client(),
_applicationContainer.BookThumbNailer, new BookDownloadStartingEvent()) /*not hooked to anything*/;
transfer.UploadFolder(args[1], _applicationContainer);
return 1;
}
InstallerSupport.MakeBloomRegistryEntries(args);
BookDownloadSupport.EnsureDownloadFolderExists();
SetUpLocalization();
if (args.Length == 1 && !IsInstallerLaunch(args))
{
Debug.Assert(args[0].ToLowerInvariant().EndsWith(".bloomcollection")); // Anything else handled above.
if (CollectionChoosing.OpenCreateCloneControl.ReportIfInvalidCollectionToEdit(args[0]))
return 1;
Settings.Default.MruProjects.AddNewPath(args[0]);
}
if (args.Length > 0 && args[0] == "--rename")
{
try
{
var pathToNewCollection = CollectionSettings.RenameCollection(args[1], args[2]);
//MessageBox.Show("Your collection has been renamed.");
Settings.Default.MruProjects.AddNewPath(pathToNewCollection);
}
catch (ApplicationException error)
{
SIL.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message);
Environment.Exit(-1);
}
catch (Exception error)
{
SIL.Reporting.ErrorReport.NotifyUserOfProblem(error,
"Bloom could not finish renaming your collection folder. Restart your computer and try again.");
Environment.Exit(-1);
}
}
Browser.SetUpXulRunner();
Browser.XulRunnerShutdown += OnXulRunnerShutdown;
#if DEBUG
StartDebugServer();
#endif
if (!BloomIntegrityDialog.CheckIntegrity())
{
Environment.Exit(-1);
}
LocalizationManager.SetUILanguage(Settings.Default.UserInterfaceLanguage, false);
// BL-1258: sometimes the newly installed fonts are not available until after Bloom restarts
// We don't even want to try to install fonts if we are installed by an admin for all users;
// it will have been installed already as part of the allUsers install.
if ((!InstallerSupport.SharedByAllUsers()) && FontInstaller.InstallFont("AndikaNewBasic"))
return 1;
Run();
}
}
}
finally
{
// Check memory one final time for the benefit of developers. The user won't see anything.
SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "Bloom finished and exiting", false);
UniqueToken.ReleaseToken();
}
return 0;
}