Bug Summary

File:Source/Core/DolphinWX/Src/ISOFile.cpp
Location:line 271, column 11
Description:Function call argument is an uninitialized value

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <string>
6#include <vector>
7#include <wx/mstream.h>
8
9#include "Common.h"
10#include "CommonPaths.h"
11
12#include "Globals.h"
13#include "FileUtil.h"
14#include "ISOFile.h"
15#include "StringUtil.h"
16#include "Hash.h"
17#include "IniFile.h"
18#include "WxUtils.h"
19
20#include "Filesystem.h"
21#include "BannerLoader.h"
22#include "FileSearch.h"
23#include "CompressedBlob.h"
24#include "ChunkFile.h"
25#include "ConfigManager.h"
26
27static const u32 CACHE_REVISION = 0x114;
28
29#define DVD_BANNER_WIDTH96 96
30#define DVD_BANNER_HEIGHT32 32
31
32static u32 g_ImageTemp[DVD_BANNER_WIDTH96 * DVD_BANNER_HEIGHT32];
33
34GameListItem::GameListItem(const std::string& _rFileName)
35 : m_FileName(_rFileName)
36 , m_emu_state(0)
37 , m_FileSize(0)
38 , m_Revision(0)
39 , m_Valid(false)
40 , m_BlobCompressed(false)
41{
42 if (LoadFromCache())
43 {
44 m_Valid = true;
45 }
46 else
47 {
48 DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_rFileName);
49
50 if (pVolume != NULL__null)
51 {
52 if (!DiscIO::IsVolumeWadFile(pVolume))
53 m_Platform = DiscIO::IsVolumeWiiDisc(pVolume) ? WII_DISC : GAMECUBE_DISC;
54 else
55 {
56 m_Platform = WII_WAD;
57 }
58
59 m_volume_names = pVolume->GetNames();
60
61 m_Country = pVolume->GetCountry();
62 m_FileSize = pVolume->GetRawSize();
63 m_VolumeSize = pVolume->GetSize();
64
65 m_UniqueID = pVolume->GetUniqueID();
66 m_BlobCompressed = DiscIO::IsCompressedBlob(_rFileName.c_str());
67 m_IsDiscTwo = pVolume->IsDiscTwo();
68 m_Revision = pVolume->GetRevision();
69
70 // check if we can get some info from the banner file too
71 DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume);
72
73 if (pFileSystem != NULL__null || m_Platform == WII_WAD)
74 {
75 DiscIO::IBannerLoader* pBannerLoader = DiscIO::CreateBannerLoader(*pFileSystem, pVolume);
76
77 if (pBannerLoader != NULL__null)
78 {
79 if (pBannerLoader->IsValid())
80 {
81 m_names = pBannerLoader->GetNames();
82 m_company = pBannerLoader->GetCompany();
83 m_descriptions = pBannerLoader->GetDescriptions();
84
85 if (pBannerLoader->GetBanner(g_ImageTemp))
86 {
87 // resize vector to image size
88 m_pImage.resize(DVD_BANNER_WIDTH96 * DVD_BANNER_HEIGHT32 * 3);
89
90 for (size_t i = 0; i < DVD_BANNER_WIDTH96 * DVD_BANNER_HEIGHT32; i++)
91 {
92 m_pImage[i * 3 + 0] = (g_ImageTemp[i] & 0xFF0000) >> 16;
93 m_pImage[i * 3 + 1] = (g_ImageTemp[i] & 0x00FF00) >> 8;
94 m_pImage[i * 3 + 2] = (g_ImageTemp[i] & 0x0000FF) >> 0;
95 }
96 }
97 }
98 delete pBannerLoader;
99 }
100
101 delete pFileSystem;
102 }
103
104 delete pVolume;
105
106 m_Valid = true;
107
108 // Create a cache file only if we have an image.
109 // Wii isos create their images after you have generated the first savegame
110 if (!m_pImage.empty())
111 SaveToCache();
112 }
113 }
114
115 if (IsValid())
116 {
117 IniFile ini;
118 ini.Load(File::GetUserPath(D_GAMECONFIG_IDX) + m_UniqueID + ".ini");
119 ini.Get("EmuState", "EmulationStateId", &m_emu_state);
120 ini.Get("EmuState", "EmulationIssues", &m_issues);
121 }
122
123 if (!m_pImage.empty())
124 {
125 m_Image.Create(DVD_BANNER_WIDTH96, DVD_BANNER_HEIGHT32, &m_pImage[0], true);
126 }
127 else
128 {
129 // default banner
130 m_Image = wxImage(StrToWxStr(File::GetThemeDir(SConfig::GetInstance().m_LocalCoreStartupParameter.theme_name)) + "nobanner.png", wxBITMAP_TYPE_PNG);
131 }
132}
133
134GameListItem::~GameListItem()
135{
136}
137
138bool GameListItem::LoadFromCache()
139{
140 return CChunkFileReader::Load<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
141}
142
143void GameListItem::SaveToCache()
144{
145 if (!File::IsDirectory(File::GetUserPath(D_CACHE_IDX)))
146 {
147 File::CreateDir(File::GetUserPath(D_CACHE_IDX));
148 }
149
150 CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
151}
152
153void GameListItem::DoState(PointerWrap &p)
154{
155 p.Do(m_volume_names);
156 p.Do(m_company);
157 p.Do(m_names);
158 p.Do(m_descriptions);
159 p.Do(m_UniqueID);
160 p.Do(m_FileSize);
161 p.Do(m_VolumeSize);
162 p.Do(m_Country);
163 p.Do(m_BlobCompressed);
164 p.Do(m_pImage);
165 p.Do(m_Platform);
166 p.Do(m_IsDiscTwo);
167 p.Do(m_Revision);
168}
169
170std::string GameListItem::CreateCacheFilename()
171{
172 std::string Filename, LegalPathname, extension;
173 SplitPath(m_FileName, &LegalPathname, &Filename, &extension);
174
175 if (Filename.empty()) return Filename; // Disc Drive
176
177 // Filename.extension_HashOfFolderPath_Size.cache
178 // Append hash to prevent ISO name-clashing in different folders.
179 Filename.append(StringFromFormat("%s_%x_%llx.cache",
180 extension.c_str(), HashFletcher((const u8 *)LegalPathname.c_str(), LegalPathname.size()),
181 File::GetSize(m_FileName)));
182
183 std::string fullname(File::GetUserPath(D_CACHE_IDX));
184 fullname += Filename;
185 return fullname;
186}
187
188std::string GameListItem::GetCompany() const
189{
190 if (m_company.empty())
191 return "N/A";
192 else
193 return m_company;
194}
195
196// (-1 = Japanese, 0 = English, etc)?
197std::string GameListItem::GetDescription(int _index) const
198{
199 const u32 index = _index;
200
201 if (index < m_descriptions.size())
202 return m_descriptions[index];
203
204 if (!m_descriptions.empty())
205 return m_descriptions[0];
206
207 return "";
208}
209
210// (-1 = Japanese, 0 = English, etc)?
211std::string GameListItem::GetVolumeName(int _index) const
212{
213 u32 const index = _index;
214
215 if (index < m_volume_names.size() && !m_volume_names[index].empty())
216 return m_volume_names[index];
217
218 if (!m_volume_names.empty())
219 return m_volume_names[0];
220
221 return "";
222}
223
224// (-1 = Japanese, 0 = English, etc)?
225std::string GameListItem::GetBannerName(int _index) const
226{
227 u32 const index = _index;
228
229 if (index < m_names.size() && !m_names[index].empty())
230 return m_names[index];
231
232 if (!m_names.empty())
233 return m_names[0];
234
235 return "";
236}
237
238// (-1 = Japanese, 0 = English, etc)?
239std::string GameListItem::GetName(int _index) const
240{
241 // Prefer name from banner, fallback to name from volume, fallback to filename
242
243 std::string name = GetBannerName(_index);
244
245 if (name.empty())
246 name = GetVolumeName(_index);
247
248 if (name.empty())
249 {
250 // No usable name, return filename (better than nothing)
251 SplitPath(GetFileName(), NULL__null, &name, NULL__null);
252 }
253
254 return name;
255}
256
257const std::string GameListItem::GetWiiFSPath() const
258{
259 DiscIO::IVolume *Iso = DiscIO::CreateVolumeFromFilename(m_FileName);
260 std::string ret;
261
262 if (Iso == NULL__null)
1
Taking false branch
263 return ret;
264
265 if (DiscIO::IsVolumeWiiDisc(Iso) || DiscIO::IsVolumeWadFile(Iso))
266 {
267 char Path[250];
268 u64 Title;
2
Variable 'Title' declared without an initial value
269
270 Iso->GetTitleID((u8*)&Title);
271 Title = Common::swap64(Title);
3
Function call argument is an uninitialized value
272
273 sprintf(Path, "%stitle/%08x/%08x/data/",
274 File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(Title>>32), (u32)Title);
275
276 if (!File::Exists(Path))
277 File::CreateFullPath(Path);
278
279 if (Path[0] == '.')
280 ret = WxStrToStr(wxGetCwd()) + std::string(Path).substr(strlen(ROOT_DIR"."));
281 else
282 ret = std::string(Path);
283 }
284 delete Iso;
285
286 return ret;
287}
288