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