/************************************************************************* * UrBackup - Client/Server backup system * Copyright (C) 2011 Martin Raiber * * 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, either version 3 of the License, or * (at your option) any later version. * * 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 for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . **************************************************************************/ #include "../vld.h" #include "file.h" #include "types.h" #include "stringtools.h" #ifdef MODE_WIN bool File::Open(std::wstring pfn, int mode) { fn=pfn; DWORD dwCreationDisposition; DWORD dwDesiredAccess; if( mode==MODE_READ ) { dwCreationDisposition=OPEN_EXISTING; dwDesiredAccess=GENERIC_READ; } else if( mode==MODE_WRITE ) { DeleteFileInt(pfn); dwCreationDisposition=CREATE_NEW; dwDesiredAccess=GENERIC_WRITE; } else if( mode==MODE_APPEND|| mode==MODE_TEMP ) { dwCreationDisposition=OPEN_EXISTING; dwDesiredAccess=GENERIC_WRITE | GENERIC_READ; } else if( mode==MODE_RW ) { dwCreationDisposition=OPEN_EXISTING; dwDesiredAccess=GENERIC_WRITE | GENERIC_READ; } hfile=CreateFileW( fn.c_str(), dwDesiredAccess, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL ); if( hfile!=INVALID_HANDLE_VALUE ) { if( mode==MODE_APPEND ) { Seek( Size() ); } return true; } else { hfile=NULL; return false; } } bool File::OpenTemporaryFile(void) { wchar_t tmpp[MAX_PATH]; DWORD l; if((l=GetTempPathW(MAX_PATH, tmpp))==0 || l>MAX_PATH ) { wcscpy_s(tmpp,L"C:\\"); } wchar_t filename[MAX_PATH]; if( GetTempFileNameW(tmpp, L"cps", 0, filename)==0 ) { hfile=NULL; int err=GetLastError(); return false; } return Open(filename, MODE_TEMP); } std::string File::Read(_u32 tr) { std::string ret; ret.resize(tr); _u32 gc=Read((char*)ret.c_str(), tr); if( gc