2013-09-13 23:05:11 +08:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2015-12-25 21:01:13 -08:00
|
|
|
#include "Common/Common.h"
|
2013-12-29 23:28:31 +01:00
|
|
|
#include "Common/ChunkFile.h"
|
2015-04-05 18:03:50 -07:00
|
|
|
#include "Core/MemMapHelpers.h"
|
2015-12-25 21:01:13 -08:00
|
|
|
#include "Core/Reporting.h"
|
2014-03-15 10:38:46 -07:00
|
|
|
#include "Core/System.h"
|
2013-12-29 23:28:31 +01:00
|
|
|
#include "Core/FileSystems/MetaFileSystem.h"
|
|
|
|
#include "Core/Dialog/PSPGamedataInstallDialog.h"
|
2013-09-13 23:05:11 +08:00
|
|
|
|
2013-09-27 22:52:25 +08:00
|
|
|
std::string saveBasePath = "ms0:/PSP/SAVEDATA/";
|
|
|
|
|
2015-12-25 21:01:13 -08:00
|
|
|
// Guesses.
|
|
|
|
const static int GAMEDATA_INIT_DELAY_US = 200000;
|
|
|
|
const static int GAMEDATA_SHUTDOWN_DELAY_US = 2000;
|
|
|
|
|
2013-09-27 22:52:25 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
std::vector<std::string> GetPSPFileList (std::string dirpath) {
|
|
|
|
std::vector<std::string> FileList;
|
|
|
|
auto Fileinfos = pspFileSystem.GetDirListing(dirpath);
|
|
|
|
|
|
|
|
for (auto it = Fileinfos.begin(); it != Fileinfos.end(); ++it) {
|
|
|
|
std::string info = (*it).name;
|
|
|
|
FileList.push_back(info);
|
|
|
|
}
|
|
|
|
return FileList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 23:05:11 +08:00
|
|
|
PSPGamedataInstallDialog::PSPGamedataInstallDialog() {
|
|
|
|
}
|
|
|
|
|
|
|
|
PSPGamedataInstallDialog::~PSPGamedataInstallDialog() {
|
|
|
|
}
|
|
|
|
|
2013-09-15 09:53:24 +02:00
|
|
|
int PSPGamedataInstallDialog::Init(u32 paramAddr) {
|
2015-12-25 21:01:13 -08:00
|
|
|
if (GetStatus() != SCE_UTILITY_STATUS_NONE) {
|
|
|
|
ERROR_LOG_REPORT(SCEUTILITY, "A game install request is already running, not starting a new one");
|
|
|
|
return SCE_ERROR_UTILITY_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
|
2013-09-27 22:52:25 +08:00
|
|
|
this->paramAddr = paramAddr;
|
2015-12-25 21:01:13 -08:00
|
|
|
inFileNames = GetPSPFileList("disc0:/PSP_GAME/INSDIR");
|
2013-10-06 21:56:25 -07:00
|
|
|
numFiles = (int)inFileNames.size();
|
2013-09-27 22:52:25 +08:00
|
|
|
readFiles = 0;
|
|
|
|
progressValue = 0;
|
|
|
|
allFilesSize = 0;
|
|
|
|
allReadSize = 0;
|
2015-12-25 21:01:13 -08:00
|
|
|
|
|
|
|
for (std::string filename : inFileNames) {
|
|
|
|
allFilesSize += pspFileSystem.GetFileInfo("disc0:/PSP_GAME/INSDIR/" + filename).size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allFilesSize == 0) {
|
|
|
|
ERROR_LOG_REPORT(SCEUTILITY, "Game install with no files / data");
|
|
|
|
// TODO: What happens here?
|
|
|
|
return -1;
|
2013-09-27 22:52:25 +08:00
|
|
|
}
|
2013-09-13 23:05:11 +08:00
|
|
|
|
|
|
|
int size = Memory::Read_U32(paramAddr);
|
|
|
|
memset(&request, 0, sizeof(request));
|
|
|
|
// Only copy the right size to support different request format
|
|
|
|
Memory::Memcpy(&request, paramAddr, size);
|
|
|
|
|
2015-12-25 21:01:13 -08:00
|
|
|
ChangeStatusInit(GAMEDATA_INIT_DELAY_US);
|
2013-09-13 23:05:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-16 18:54:17 +02:00
|
|
|
int PSPGamedataInstallDialog::Update(int animSpeed) {
|
2015-12-25 21:01:13 -08:00
|
|
|
if (GetStatus() != SCE_UTILITY_STATUS_RUNNING)
|
|
|
|
return SCE_ERROR_UTILITY_INVALID_STATUS;
|
|
|
|
|
|
|
|
std::string fullinFileName;
|
|
|
|
std::string outFileName;
|
|
|
|
u64 totalLength;
|
|
|
|
u64 restLength;
|
|
|
|
u32 bytesToRead = 4096;
|
|
|
|
u32 inhandle;
|
|
|
|
u32 outhandle;
|
|
|
|
size_t readSize;
|
2013-09-27 22:52:25 +08:00
|
|
|
|
2015-12-25 21:01:13 -08:00
|
|
|
if (readFiles < numFiles) {
|
|
|
|
u8 *temp = new u8[4096];
|
|
|
|
fullinFileName = "disc0:/PSP_GAME/INSDIR/" + inFileNames[readFiles];
|
|
|
|
outFileName = GetGameDataInstallFileName(&request, inFileNames[readFiles]);
|
|
|
|
totalLength = pspFileSystem.GetFileInfo(fullinFileName).size;
|
|
|
|
restLength = totalLength;
|
|
|
|
inhandle = pspFileSystem.OpenFile(fullinFileName, FILEACCESS_READ);
|
|
|
|
if (inhandle != 0) {
|
|
|
|
outhandle = pspFileSystem.OpenFile(outFileName, (FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE | FILEACCESS_TRUNCATE));
|
|
|
|
if (outhandle != 0) {
|
|
|
|
while (restLength > 0) {
|
|
|
|
if (restLength < bytesToRead)
|
|
|
|
bytesToRead = (u32)restLength;
|
|
|
|
readSize = pspFileSystem.ReadFile(inhandle, temp, bytesToRead);
|
|
|
|
if(readSize > 0) {
|
|
|
|
pspFileSystem.WriteFile(outhandle, temp, readSize);
|
|
|
|
restLength -= readSize;
|
|
|
|
allReadSize += readSize;
|
|
|
|
} else
|
|
|
|
break;
|
2013-09-27 22:52:25 +08:00
|
|
|
}
|
2015-12-25 21:01:13 -08:00
|
|
|
pspFileSystem.CloseFile(outhandle);
|
2013-09-27 22:52:25 +08:00
|
|
|
}
|
2015-12-25 21:01:13 -08:00
|
|
|
++readFiles;
|
|
|
|
pspFileSystem.CloseFile(inhandle);
|
2013-09-27 22:52:25 +08:00
|
|
|
}
|
2015-12-25 21:01:13 -08:00
|
|
|
UpdateProgress();
|
|
|
|
delete[] temp;
|
|
|
|
} else {
|
|
|
|
//What is this?
|
|
|
|
request.unknownResult1 = readFiles;
|
|
|
|
request.unknownResult2 = readFiles;
|
|
|
|
Memory::WriteStruct(paramAddr,&request);
|
|
|
|
|
|
|
|
ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0);
|
|
|
|
}
|
2013-09-27 22:52:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-15 09:53:24 +02:00
|
|
|
int PSPGamedataInstallDialog::Abort() {
|
2015-12-25 21:01:13 -08:00
|
|
|
// TODO: Delete the files or anything?
|
2013-09-13 23:05:11 +08:00
|
|
|
return PSPDialog::Shutdown();
|
|
|
|
}
|
|
|
|
|
2013-09-15 09:53:24 +02:00
|
|
|
int PSPGamedataInstallDialog::Shutdown(bool force) {
|
2015-12-25 21:01:13 -08:00
|
|
|
if (GetStatus() != SCE_UTILITY_STATUS_FINISHED && !force)
|
2013-09-15 09:53:24 +02:00
|
|
|
return SCE_ERROR_UTILITY_INVALID_STATUS;
|
2013-09-13 23:05:11 +08:00
|
|
|
|
2015-03-28 13:01:10 -07:00
|
|
|
return PSPDialog::Shutdown(force);
|
2013-09-13 23:05:11 +08:00
|
|
|
}
|
|
|
|
|
2013-09-27 22:52:25 +08:00
|
|
|
std::string PSPGamedataInstallDialog::GetGameDataInstallFileName(SceUtilityGamedataInstallParam *param, std::string filename){
|
|
|
|
if (!param)
|
|
|
|
return "";
|
|
|
|
std::string GameDataInstallPath = saveBasePath + param->gameName + param->dataName + "/";
|
|
|
|
if (!pspFileSystem.GetFileInfo(GameDataInstallPath).exists)
|
|
|
|
pspFileSystem.MkDir(GameDataInstallPath);
|
|
|
|
|
|
|
|
return GameDataInstallPath + filename;
|
|
|
|
}
|
|
|
|
|
2015-12-25 21:01:13 -08:00
|
|
|
void PSPGamedataInstallDialog::UpdateProgress() {
|
2013-09-27 22:52:25 +08:00
|
|
|
// Update progress bar(if there is).
|
|
|
|
// We only should update progress[0] here as the max progress value is 100.
|
2013-11-26 23:45:45 +08:00
|
|
|
if (allFilesSize != 0)
|
|
|
|
progressValue = (int)(allReadSize / allFilesSize) * 100;
|
|
|
|
else
|
|
|
|
progressValue = 100;
|
2015-12-25 21:01:13 -08:00
|
|
|
request.progress = progressValue;
|
|
|
|
Memory::WriteStruct(paramAddr, &request);
|
2013-09-27 22:52:25 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 23:05:11 +08:00
|
|
|
void PSPGamedataInstallDialog::DoState(PointerWrap &p) {
|
2013-09-27 23:57:08 +08:00
|
|
|
auto s = p.Section("PSPGamedataInstallDialog", 0, 2);
|
2013-09-15 09:53:24 +02:00
|
|
|
if (!s)
|
|
|
|
return;
|
2013-09-27 22:40:04 -07:00
|
|
|
|
|
|
|
// This was included in version 1 and higher.
|
|
|
|
PSPDialog::DoState(p);
|
|
|
|
p.Do(request);
|
|
|
|
|
|
|
|
// This was included in version 2 and higher.
|
2013-09-27 23:57:08 +08:00
|
|
|
if (s > 2) {
|
|
|
|
p.Do(paramAddr);
|
|
|
|
p.Do(inFileNames);
|
|
|
|
p.Do(numFiles);
|
|
|
|
p.Do(readFiles);
|
|
|
|
p.Do(allFilesSize);
|
|
|
|
p.Do(allReadSize);
|
|
|
|
p.Do(progressValue);
|
|
|
|
} else {
|
|
|
|
paramAddr = 0;
|
|
|
|
}
|
2013-12-29 23:28:31 +01:00
|
|
|
}
|