Bumping manifests a=b2g-bump
[gecko.git] / xpcom / glue / AppData.cpp
blobef9eb3c1dad8882d2bfe3f5c70fac3824e850384
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/AppData.h"
8 #include "nsXULAppAPI.h"
9 #include "nsINIParser.h"
10 #include "nsIFile.h"
11 #include "nsCRTGlue.h"
12 #include "nsAutoPtr.h"
14 namespace mozilla {
16 void
17 SetAllocatedString(const char*& aStr, const char* aNewValue)
19 NS_Free(const_cast<char*>(aStr));
20 if (aNewValue) {
21 aStr = NS_strdup(aNewValue);
22 } else {
23 aStr = nullptr;
27 void
28 SetAllocatedString(const char*& aStr, const nsACString& aNewValue)
30 NS_Free(const_cast<char*>(aStr));
31 if (aNewValue.IsEmpty()) {
32 aStr = nullptr;
33 } else {
34 aStr = ToNewCString(aNewValue);
38 ScopedAppData::ScopedAppData(const nsXREAppData* aAppData)
40 Zero();
42 this->size = aAppData->size;
44 SetAllocatedString(this->vendor, aAppData->vendor);
45 SetAllocatedString(this->name, aAppData->name);
46 SetAllocatedString(this->version, aAppData->version);
47 SetAllocatedString(this->buildID, aAppData->buildID);
48 SetAllocatedString(this->ID, aAppData->ID);
49 SetAllocatedString(this->copyright, aAppData->copyright);
50 SetAllocatedString(this->profile, aAppData->profile);
51 SetStrongPtr(this->directory, aAppData->directory);
52 this->flags = aAppData->flags;
54 if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) {
55 SetStrongPtr(this->xreDirectory, aAppData->xreDirectory);
56 SetAllocatedString(this->minVersion, aAppData->minVersion);
57 SetAllocatedString(this->maxVersion, aAppData->maxVersion);
60 if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
61 SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL);
64 if (aAppData->size > offsetof(nsXREAppData, UAName)) {
65 SetAllocatedString(this->UAName, aAppData->UAName);
69 ScopedAppData::~ScopedAppData()
71 SetAllocatedString(this->vendor, nullptr);
72 SetAllocatedString(this->name, nullptr);
73 SetAllocatedString(this->version, nullptr);
74 SetAllocatedString(this->buildID, nullptr);
75 SetAllocatedString(this->ID, nullptr);
76 SetAllocatedString(this->copyright, nullptr);
77 SetAllocatedString(this->profile, nullptr);
79 NS_IF_RELEASE(this->directory);
81 SetStrongPtr(this->xreDirectory, (nsIFile*)nullptr);
82 SetAllocatedString(this->minVersion, nullptr);
83 SetAllocatedString(this->maxVersion, nullptr);
85 SetAllocatedString(this->crashReporterURL, nullptr);
86 SetAllocatedString(this->UAName, nullptr);
89 } // namespace mozilla