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"
10 #include "mozilla/AppData.h"
12 using namespace mozilla
;
15 XRE_CreateAppData(nsIFile
* aINIFile
, nsXREAppData
**aAppData
)
17 NS_ENSURE_ARG(aINIFile
&& aAppData
);
19 nsAutoPtr
<ScopedAppData
> data(new ScopedAppData());
21 return NS_ERROR_OUT_OF_MEMORY
;
23 nsresult rv
= XRE_ParseAppData(aINIFile
, data
);
27 if (!data
->directory
) {
28 nsCOMPtr
<nsIFile
> appDir
;
29 rv
= aINIFile
->GetParent(getter_AddRefs(appDir
));
33 appDir
.forget(&data
->directory
);
36 *aAppData
= data
.forget();
47 ReadStrings(nsINIParser
&parser
, const ReadString
*reads
)
52 while (reads
->section
) {
53 rv
= parser
.GetString(reads
->section
, reads
->key
, str
);
54 if (NS_SUCCEEDED(rv
)) {
55 SetAllocatedString(*reads
->buffer
, str
);
69 ReadFlags(nsINIParser
&parser
, const ReadFlag
*reads
, uint32_t *buffer
)
72 char buf
[6]; // large enough to hold "false"
74 while (reads
->section
) {
75 rv
= parser
.GetString(reads
->section
, reads
->key
, buf
, sizeof(buf
));
76 if (NS_SUCCEEDED(rv
) || rv
== NS_ERROR_LOSS_OF_SIGNIFICANT_DATA
) {
77 if (buf
[0] == '1' || buf
[0] == 't' || buf
[0] == 'T') {
78 *buffer
|= reads
->flag
;
80 if (buf
[0] == '0' || buf
[0] == 'f' || buf
[0] == 'F') {
81 *buffer
&= ~reads
->flag
;
90 XRE_ParseAppData(nsIFile
* aINIFile
, nsXREAppData
*aAppData
)
92 NS_ENSURE_ARG(aINIFile
&& aAppData
);
97 rv
= parser
.Init(aINIFile
);
103 ReadString strings
[] = {
104 { "App", "Vendor", &aAppData
->vendor
},
105 { "App", "Name", &aAppData
->name
},
106 { "App", "Version", &aAppData
->version
},
107 { "App", "BuildID", &aAppData
->buildID
},
108 { "App", "ID", &aAppData
->ID
},
109 { "App", "Copyright", &aAppData
->copyright
},
110 { "App", "Profile", &aAppData
->profile
},
113 ReadStrings(parser
, strings
);
116 { "XRE", "EnableProfileMigrator", NS_XRE_ENABLE_PROFILE_MIGRATOR
},
117 { "XRE", "EnableExtensionManager", NS_XRE_ENABLE_EXTENSION_MANAGER
},
120 ReadFlags(parser
, flags
, &aAppData
->flags
);
122 if (aAppData
->size
> offsetof(nsXREAppData
, xreDirectory
)) {
123 ReadString strings2
[] = {
124 { "Gecko", "MinVersion", &aAppData
->minVersion
},
125 { "Gecko", "MaxVersion", &aAppData
->maxVersion
},
128 ReadStrings(parser
, strings2
);
131 if (aAppData
->size
> offsetof(nsXREAppData
, crashReporterURL
)) {
132 ReadString strings3
[] = {
133 { "Crash Reporter", "ServerURL", &aAppData
->crashReporterURL
},
136 ReadStrings(parser
, strings3
);
137 ReadFlag flags2
[] = {
138 { "Crash Reporter", "Enabled", NS_XRE_ENABLE_CRASH_REPORTER
},
141 ReadFlags(parser
, flags2
, &aAppData
->flags
);
144 if (aAppData
->size
> offsetof(nsXREAppData
, UAName
)) {
145 ReadString strings4
[] = {
146 { "App", "UAName", &aAppData
->UAName
},
149 ReadStrings(parser
, strings4
);
156 XRE_FreeAppData(nsXREAppData
*aAppData
)
159 NS_ERROR("Invalid arg");
163 ScopedAppData
* sad
= static_cast<ScopedAppData
*>(aAppData
);