2012-06-08 12:41:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2006-08-17 14:22:04 +00:00
|
|
|
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#include "nsINIParser.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2007-07-25 20:24:37 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2012-06-08 12:41:30 +00:00
|
|
|
#include "mozilla/AppData.h"
|
2006-08-17 14:22:04 +00:00
|
|
|
|
2012-06-08 12:41:30 +00:00
|
|
|
using namespace mozilla;
|
2006-08-17 14:22:04 +00:00
|
|
|
|
|
|
|
nsresult
|
2012-06-06 02:08:30 +00:00
|
|
|
XRE_CreateAppData(nsIFile* aINIFile, nsXREAppData **aAppData)
|
2006-08-17 14:22:04 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aINIFile && aAppData);
|
|
|
|
|
2007-07-25 20:46:15 +00:00
|
|
|
nsAutoPtr<ScopedAppData> data(new ScopedAppData());
|
2006-08-17 14:22:04 +00:00
|
|
|
if (!data)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsresult rv = XRE_ParseAppData(aINIFile, data);
|
2007-07-25 20:24:37 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!data->directory) {
|
|
|
|
nsCOMPtr<nsIFile> appDir;
|
|
|
|
rv = aINIFile->GetParent(getter_AddRefs(appDir));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-06-08 12:41:30 +00:00
|
|
|
appDir.forget(&data->directory);
|
2006-08-17 14:22:04 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 20:24:37 +00:00
|
|
|
*aAppData = data.forget();
|
|
|
|
return NS_OK;
|
2006-08-17 14:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ReadString {
|
|
|
|
const char *section;
|
|
|
|
const char *key;
|
|
|
|
const char **buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
ReadStrings(nsINIParser &parser, const ReadString *reads)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCString str;
|
|
|
|
|
|
|
|
while (reads->section) {
|
|
|
|
rv = parser.GetString(reads->section, reads->key, str);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetAllocatedString(*reads->buffer, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
++reads;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ReadFlag {
|
|
|
|
const char *section;
|
|
|
|
const char *key;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flag;
|
2006-08-17 14:22:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2012-08-22 15:56:38 +00:00
|
|
|
ReadFlags(nsINIParser &parser, const ReadFlag *reads, uint32_t *buffer)
|
2006-08-17 14:22:04 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
char buf[6]; // large enough to hold "false"
|
|
|
|
|
|
|
|
while (reads->section) {
|
|
|
|
rv = parser.GetString(reads->section, reads->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') {
|
|
|
|
*buffer |= reads->flag;
|
|
|
|
}
|
|
|
|
if (buf[0] == '0' || buf[0] == 'f' || buf[0] == 'F') {
|
|
|
|
*buffer &= ~reads->flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++reads;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-06-06 02:08:30 +00:00
|
|
|
XRE_ParseAppData(nsIFile* aINIFile, nsXREAppData *aAppData)
|
2006-08-17 14:22:04 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aINIFile && aAppData);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsINIParser parser;
|
|
|
|
rv = parser.Init(aINIFile);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCString str;
|
|
|
|
|
|
|
|
ReadString strings[] = {
|
2014-09-23 18:49:03 +00:00
|
|
|
{ "App", "Vendor", &aAppData->vendor },
|
|
|
|
{ "App", "Name", &aAppData->name },
|
|
|
|
{ "App", "RemotingName", &aAppData->remotingName },
|
|
|
|
{ "App", "Version", &aAppData->version },
|
|
|
|
{ "App", "BuildID", &aAppData->buildID },
|
|
|
|
{ "App", "ID", &aAppData->ID },
|
|
|
|
{ "App", "Copyright", &aAppData->copyright },
|
|
|
|
{ "App", "Profile", &aAppData->profile },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2006-08-17 14:22:04 +00:00
|
|
|
};
|
|
|
|
ReadStrings(parser, strings);
|
|
|
|
|
|
|
|
ReadFlag flags[] = {
|
|
|
|
{ "XRE", "EnableProfileMigrator", NS_XRE_ENABLE_PROFILE_MIGRATOR },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2006-08-17 14:22:04 +00:00
|
|
|
};
|
|
|
|
ReadFlags(parser, flags, &aAppData->flags);
|
|
|
|
|
|
|
|
if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) {
|
|
|
|
ReadString strings2[] = {
|
|
|
|
{ "Gecko", "MinVersion", &aAppData->minVersion },
|
|
|
|
{ "Gecko", "MaxVersion", &aAppData->maxVersion },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2006-08-17 14:22:04 +00:00
|
|
|
};
|
|
|
|
ReadStrings(parser, strings2);
|
|
|
|
}
|
|
|
|
|
2007-05-16 17:14:59 +00:00
|
|
|
if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
|
|
|
|
ReadString strings3[] = {
|
|
|
|
{ "Crash Reporter", "ServerURL", &aAppData->crashReporterURL },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2007-05-16 17:14:59 +00:00
|
|
|
};
|
|
|
|
ReadStrings(parser, strings3);
|
|
|
|
ReadFlag flags2[] = {
|
|
|
|
{ "Crash Reporter", "Enabled", NS_XRE_ENABLE_CRASH_REPORTER },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2007-05-16 17:14:59 +00:00
|
|
|
};
|
|
|
|
ReadFlags(parser, flags2, &aAppData->flags);
|
|
|
|
}
|
|
|
|
|
2012-04-23 20:09:23 +00:00
|
|
|
if (aAppData->size > offsetof(nsXREAppData, UAName)) {
|
|
|
|
ReadString strings4[] = {
|
|
|
|
{ "App", "UAName", &aAppData->UAName },
|
2012-07-30 14:20:58 +00:00
|
|
|
{ nullptr }
|
2012-04-23 20:09:23 +00:00
|
|
|
};
|
|
|
|
ReadStrings(parser, strings4);
|
|
|
|
}
|
|
|
|
|
2006-08-17 14:22:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
XRE_FreeAppData(nsXREAppData *aAppData)
|
|
|
|
{
|
|
|
|
if (!aAppData) {
|
|
|
|
NS_ERROR("Invalid arg");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
ScopedAppData* sad = static_cast<ScopedAppData*>(aAppData);
|
2006-08-17 14:22:04 +00:00
|
|
|
delete sad;
|
|
|
|
}
|