|
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/. */ |
|
5 |
|
6 #include "mozilla/AppData.h" |
|
7 #include "nsXULAppAPI.h" |
|
8 #include "nsINIParser.h" |
|
9 #include "nsIFile.h" |
|
10 #include "nsCRTGlue.h" |
|
11 #include "nsAutoPtr.h" |
|
12 |
|
13 namespace mozilla { |
|
14 |
|
15 void |
|
16 SetAllocatedString(const char *&str, const char *newvalue) |
|
17 { |
|
18 NS_Free(const_cast<char*>(str)); |
|
19 if (newvalue) { |
|
20 str = NS_strdup(newvalue); |
|
21 } |
|
22 else { |
|
23 str = nullptr; |
|
24 } |
|
25 } |
|
26 |
|
27 void |
|
28 SetAllocatedString(const char *&str, const nsACString &newvalue) |
|
29 { |
|
30 NS_Free(const_cast<char*>(str)); |
|
31 if (newvalue.IsEmpty()) { |
|
32 str = nullptr; |
|
33 } |
|
34 else { |
|
35 str = ToNewCString(newvalue); |
|
36 } |
|
37 } |
|
38 |
|
39 ScopedAppData::ScopedAppData(const nsXREAppData* aAppData) |
|
40 { |
|
41 Zero(); |
|
42 |
|
43 this->size = aAppData->size; |
|
44 |
|
45 SetAllocatedString(this->vendor, aAppData->vendor); |
|
46 SetAllocatedString(this->name, aAppData->name); |
|
47 SetAllocatedString(this->version, aAppData->version); |
|
48 SetAllocatedString(this->buildID, aAppData->buildID); |
|
49 SetAllocatedString(this->ID, aAppData->ID); |
|
50 SetAllocatedString(this->copyright, aAppData->copyright); |
|
51 SetAllocatedString(this->profile, aAppData->profile); |
|
52 SetStrongPtr(this->directory, aAppData->directory); |
|
53 this->flags = aAppData->flags; |
|
54 |
|
55 if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) { |
|
56 SetStrongPtr(this->xreDirectory, aAppData->xreDirectory); |
|
57 SetAllocatedString(this->minVersion, aAppData->minVersion); |
|
58 SetAllocatedString(this->maxVersion, aAppData->maxVersion); |
|
59 } |
|
60 |
|
61 if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) { |
|
62 SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL); |
|
63 } |
|
64 |
|
65 if (aAppData->size > offsetof(nsXREAppData, UAName)) { |
|
66 SetAllocatedString(this->UAName, aAppData->UAName); |
|
67 } |
|
68 } |
|
69 |
|
70 ScopedAppData::~ScopedAppData() |
|
71 { |
|
72 SetAllocatedString(this->vendor, nullptr); |
|
73 SetAllocatedString(this->name, nullptr); |
|
74 SetAllocatedString(this->version, nullptr); |
|
75 SetAllocatedString(this->buildID, nullptr); |
|
76 SetAllocatedString(this->ID, nullptr); |
|
77 SetAllocatedString(this->copyright, nullptr); |
|
78 SetAllocatedString(this->profile, nullptr); |
|
79 |
|
80 NS_IF_RELEASE(this->directory); |
|
81 |
|
82 SetStrongPtr(this->xreDirectory, (nsIFile*) nullptr); |
|
83 SetAllocatedString(this->minVersion, nullptr); |
|
84 SetAllocatedString(this->maxVersion, nullptr); |
|
85 |
|
86 SetAllocatedString(this->crashReporterURL, nullptr); |
|
87 SetAllocatedString(this->UAName, nullptr); |
|
88 } |
|
89 |
|
90 } // namespace mozilla |