Fixed problem with utf characters in the %APPDATA% path on Windows.

Added function for opening files on Windows and Linux - RsDirUtil::rs_fopen.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4124 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-04-03 23:11:38 +00:00
parent bc78397a64
commit bc113326e4
17 changed files with 109 additions and 119 deletions

View file

@ -682,7 +682,7 @@ bool ftController::moveFile(const std::string& source,const std::string& dest)
bool ftController::copyFile(const std::string& source,const std::string& dest)
{
FILE *in = fopen64(source.c_str(),"rb") ;
FILE *in = RsDirUtil::rs_fopen(source.c_str(),"rb") ;
if(in == NULL)
{
@ -690,7 +690,7 @@ bool ftController::copyFile(const std::string& source,const std::string& dest)
return false ;
}
FILE *out = fopen64(dest.c_str(),"wb") ;
FILE *out = RsDirUtil::rs_fopen(dest.c_str(),"wb") ;
if(out == NULL)
{
@ -1040,13 +1040,7 @@ bool ftController::FileRequest(const std::string& fname, const std::string& has
destination = dest + "/" + fname;
// create void file with the target name.
#ifdef WINDOWS_SYS
std::wstring destinationW;
librs::util::ConvertUtf8ToUtf16(destination, destinationW);
FILE *f = _wfopen(destinationW.c_str(), L"w");
#else
FILE *f = fopen64(destination.c_str(),"w") ;
#endif
FILE *f = RsDirUtil::rs_fopen(destination.c_str(),"w") ;
if(f == NULL)
std::cerr << "Could not open file " << destination << " for writting." << std::endl ;
else

View file

@ -215,7 +215,7 @@ bool ftExtraList::moveExtraFile(std::string fname, std::string hash, uint64_t si
}
std::string path = destpath + '/' + fname;
if (0 == rename(it->second.info.path.c_str(), path.c_str()))
if (RsDirUtil::renameFile(it->second.info.path, path))
{
/* rename */
it->second.info.path = path;
@ -427,13 +427,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
}
/* open file */
#ifdef WINDOWS_SYS
std::wstring filepathW;
librs::util::ConvertUtf8ToUtf16(fi->file.path, filepathW);
FILE *fd = _wfopen(filepathW.c_str(), L"rb");
#else
FILE *fd = fopen64(fi->file.path.c_str(), "rb");
#endif
FILE *fd = RsDirUtil::rs_fopen(fi->file.path.c_str(), "rb");
if (fd == NULL)
{
delete (*it);

View file

@ -251,13 +251,7 @@ int ftFileCreator::locked_initializeFileAttrs()
* attempt to open file
*/
#ifdef WINDOWS_SYS
std::wstring wfile_name;
librs::util::ConvertUtf8ToUtf16(file_name, wfile_name);
fd = _wfopen(wfile_name.c_str(), L"r+b");
#else
fd = fopen64(file_name.c_str(), "r+b");
#endif
fd = RsDirUtil::rs_fopen(file_name.c_str(), "r+b");
if (!fd)
{
@ -268,11 +262,7 @@ int ftFileCreator::locked_initializeFileAttrs()
std::cerr << std::endl;
/* try opening for write */
#ifdef WINDOWS_SYS
fd = _wfopen(wfile_name.c_str(), L"w+b");
#else
fd = fopen64(file_name.c_str(), "w+b");
#endif
fd = RsDirUtil::rs_fopen(file_name.c_str(), "w+b");
if (!fd)
{
std::cerr << "ftFileCreator::initializeFileAttrs()";

View file

@ -305,24 +305,14 @@ int ftFileProvider::initializeFileAttrs()
* attempt to open file
*/
#ifdef WINDOWS_SYS
std::wstring wfile_name;
librs::util::ConvertUtf8ToUtf16(file_name, wfile_name);
fd = _wfopen(wfile_name.c_str(), L"r+b");
#else
fd = fopen64(file_name.c_str(), "r+b");
#endif
fd = RsDirUtil::rs_fopen(file_name.c_str(), "r+b");
if (!fd)
{
std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (r+b): ";
std::cerr << file_name << std::endl;
/* try opening read only */
#ifdef WINDOWS_SYS
fd = _wfopen(wfile_name.c_str(), L"rb");
#else
fd = fopen64(file_name.c_str(), "rb");
#endif
fd = RsDirUtil::rs_fopen(file_name.c_str(), "rb");
if (!fd)
{
std::cerr << "ftFileProvider::initializeFileAttrs() Failed to open (rb): ";