Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / toolkit / xre / CreateAppData.cpp
blobdda5b3787372033bcf37af43a7eaad9568c9ee44
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsXULAppAPI.h"
7 #include "nsINIParser.h"
8 #include "nsIFile.h"
9 #include "mozilla/XREAppData.h"
11 // This include must appear early in the unified cpp file for toolkit/xre to
12 // make sure OSX APIs make use of the OSX TextRange before mozilla::TextRange is
13 // declared and made a global symbol by a "using namespace mozilla" declaration.
14 #ifdef XP_MACOSX
15 # include <Carbon/Carbon.h>
16 #endif
18 using namespace mozilla;
20 static void ReadString(nsINIParser& parser, const char* section,
21 const char* key, XREAppData::CharPtr& result) {
22 nsCString str;
23 nsresult rv = parser.GetString(section, key, str);
24 if (NS_SUCCEEDED(rv)) {
25 result = str.get();
29 struct ReadFlag {
30 const char* section;
31 const char* key;
32 uint32_t flag;
35 static void ReadFlag(nsINIParser& parser, const char* section, const char* key,
36 uint32_t flag, uint32_t& result) {
37 char buf[6]; // large enough to hold "false"
38 nsresult rv = parser.GetString(section, key, buf, sizeof(buf));
39 if (NS_SUCCEEDED(rv) || rv == NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
40 if (buf[0] == '1' || buf[0] == 't' || buf[0] == 'T') {
41 result |= flag;
43 if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
44 result &= ~flag;
49 nsresult XRE_ParseAppData(nsIFile* aINIFile, XREAppData& aAppData) {
50 NS_ENSURE_ARG(aINIFile);
52 nsresult rv;
54 nsINIParser parser;
55 rv = parser.Init(aINIFile);
56 if (NS_FAILED(rv)) return rv;
58 ReadString(parser, "App", "Vendor", aAppData.vendor);
59 ReadString(parser, "App", "Name", aAppData.name);
60 ReadString(parser, "App", "RemotingName", aAppData.remotingName);
61 ReadString(parser, "App", "Version", aAppData.version);
62 ReadString(parser, "App", "BuildID", aAppData.buildID);
63 ReadString(parser, "App", "ID", aAppData.ID);
64 ReadString(parser, "App", "Copyright", aAppData.copyright);
65 ReadString(parser, "App", "Profile", aAppData.profile);
66 ReadString(parser, "Gecko", "MinVersion", aAppData.minVersion);
67 ReadString(parser, "Gecko", "MaxVersion", aAppData.maxVersion);
68 ReadString(parser, "Crash Reporter", "ServerURL", aAppData.crashReporterURL);
69 ReadString(parser, "App", "UAName", aAppData.UAName);
70 ReadString(parser, "AppUpdate", "URL", aAppData.updateURL);
71 ReadFlag(parser, "XRE", "EnableProfileMigrator",
72 NS_XRE_ENABLE_PROFILE_MIGRATOR, aAppData.flags);
73 ReadFlag(parser, "Crash Reporter", "Enabled", NS_XRE_ENABLE_CRASH_REPORTER,
74 aAppData.flags);
76 return NS_OK;