mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-05 20:24:01 +01:00
sceIoRename function
This commit is contained in:
1 parent
156cfc4e6a
commit
6192bdf6df
7 files changed
+56
-15
No files matched your search
@@ -35,17 +35,16 @@ std::string DirectoryFileSystem::GetLocalPath(std::string localpath)
|
||||
if (localpath.empty())
|
||||
return basePath;
|
||||
|
||||
if (localpath[0] == '/')
|
||||
localpath.erase(0,1);
|
||||
if (localpath[0] == '/')
|
||||
localpath.erase(0,1);
|
||||
//Convert slashes
|
||||
#ifdef _WIN32
|
||||
for (size_t i = 0; i < localpath.size(); i++)
|
||||
{
|
||||
if (localpath[i] == '/')
|
||||
localpath[i] = '\\';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return basePath + localpath;
|
||||
}
|
||||
|
||||
@@ -56,8 +55,8 @@ bool DirectoryFileSystem::MkDir(const std::string &dirname)
|
||||
#ifdef _WIN32
|
||||
return CreateDirectory(fullName.c_str(), NULL) == TRUE;
|
||||
#else
|
||||
mkdir(fullName.c_str(), 0777);
|
||||
return true;
|
||||
mkdir(fullName.c_str(), 0777);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -67,7 +66,26 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname)
|
||||
#ifdef _WIN32
|
||||
return RemoveDirectory(fullName.c_str()) == TRUE;
|
||||
#else
|
||||
return 0 == rmdir(fullName.c_str());
|
||||
return 0 == rmdir(fullName.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DirectoryFileSystem::RenameFile(const std::string &from, const std::string &to)
|
||||
{
|
||||
std::string fullFrom = GetLocalPath(from);
|
||||
std::string fullTo = to;
|
||||
// TO filename may not include path. Intention is that it uses FROM's path
|
||||
if (to.find("/") != std::string::npos) {
|
||||
int offset = from.find_last_of("/");
|
||||
if (offset >= 0) {
|
||||
fullTo = from.substr(0, offset + 1) + to;
|
||||
}
|
||||
}
|
||||
fullTo = GetLocalPath(fullTo);
|
||||
#ifdef _WIN32
|
||||
return MoveFile(fullFrom.c_str(), fullTo.c_str()) == TRUE;
|
||||
#else
|
||||
return 0 == rename(fullFrom.c_str(), fullTo.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -77,7 +95,7 @@ bool DirectoryFileSystem::DeleteFile(const std::string &filename)
|
||||
#ifdef _WIN32
|
||||
return DeleteFile(fullName.c_str()) == TRUE;
|
||||
#else
|
||||
return 0 == unlink(fullName.c_str());
|
||||
return 0 == unlink(fullName.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -243,7 +261,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename)
|
||||
x.name = filename;
|
||||
|
||||
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
if (!File::Exists(fullName)) {
|
||||
return x;
|
||||
}
|
||||
@@ -257,8 +275,8 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename)
|
||||
|
||||
x.size = data.nFileSizeLow | ((u64)data.nFileSizeHigh<<32);
|
||||
#else
|
||||
x.size = File::GetSize(fullName);
|
||||
//TODO
|
||||
x.size = File::GetSize(fullName);
|
||||
//TODO
|
||||
#endif
|
||||
|
||||
return x;
|
||||
|
||||
@@ -36,7 +36,7 @@ class DirectoryFileSystem : public IFileSystem
|
||||
#ifdef _WIN32
|
||||
HANDLE hFile;
|
||||
#else
|
||||
FILE *hFile;
|
||||
FILE *hFile;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
bool OwnsHandle(u32 handle);
|
||||
bool MkDir(const std::string &dirname);
|
||||
bool RmDir(const std::string &dirname);
|
||||
bool RenameFile(const std::string &from, const std::string &to);
|
||||
bool DeleteFile(const std::string &filename);
|
||||
};
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
virtual bool OwnsHandle(u32 handle) = 0;
|
||||
virtual bool MkDir(const std::string &dirname) = 0;
|
||||
virtual bool RmDir(const std::string &dirname) = 0;
|
||||
virtual bool RenameFile(const std::string &from, const std::string &to) = 0;
|
||||
virtual bool DeleteFile(const std::string &filename) = 0;
|
||||
};
|
||||
|
||||
@@ -100,6 +101,7 @@ public:
|
||||
bool OwnsHandle(u32 handle) {return false;}
|
||||
virtual bool MkDir(const std::string &dirname) {return false;}
|
||||
virtual bool RmDir(const std::string &dirname) {return false;}
|
||||
virtual bool RenameFile(const std::string &from, const std::string &to) {return false;}
|
||||
virtual bool DeleteFile(const std::string &filename) {return false;}
|
||||
};
|
||||
|
||||
|
||||
@@ -82,5 +82,6 @@ public:
|
||||
|
||||
virtual bool MkDir(const std::string &dirname) {return false;}
|
||||
virtual bool RmDir(const std::string &dirname) {return false;}
|
||||
virtual bool RenameFile(const std::string &from, const std::string &to) {return false;}
|
||||
virtual bool DeleteFile(const std::string &filename) {return false;}
|
||||
};
|
||||
@@ -177,6 +177,21 @@ bool MetaFileSystem::RmDir(const std::string &dirname)
|
||||
}
|
||||
}
|
||||
|
||||
bool MetaFileSystem::RenameFile(const std::string &from, const std::string &to)
|
||||
{
|
||||
std::string of;
|
||||
std::string rf;
|
||||
IFileSystem *system;
|
||||
if (MapFilePath(from, of, &system) && MapFilePath(to, rf, &system))
|
||||
{
|
||||
return system->RenameFile(of, rf);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool MetaFileSystem::DeleteFile(const std::string &filename)
|
||||
{
|
||||
std::string of;
|
||||
|
||||
@@ -56,6 +56,7 @@ public:
|
||||
|
||||
virtual bool MkDir(const std::string &dirname);
|
||||
virtual bool RmDir(const std::string &dirname);
|
||||
virtual bool RenameFile(const std::string &from, const std::string &to);
|
||||
virtual bool DeleteFile(const std::string &filename);
|
||||
|
||||
// TODO: void IoCtl(...)
|
||||
|
||||
+5
-2
@@ -700,8 +700,11 @@ void sceIoRename() //(const char *oldname, const char *newname);
|
||||
{
|
||||
const char *from = Memory::GetCharPointer(PARAM(0));
|
||||
const char *to = Memory::GetCharPointer(PARAM(1));
|
||||
ERROR_LOG(HLE,"UNIMPL sceIoRename(%s, %s)", from, to);
|
||||
RETURN(0);
|
||||
if (pspFileSystem.RenameFile(from, to))
|
||||
RETURN(0);
|
||||
else
|
||||
RETURN(-1);
|
||||
DEBUG_LOG(HLE,"sceIoRename(%s, %s)", from, to);
|
||||
}
|
||||
|
||||
void sceIoChdir()
|
||||
|
||||
Reference in new issue
Block a user