static BOOL RemoveFile (LPTSTR lpFileName, DWORD dwFlags, WIN32_FIND_DATA* f) { /*This function is called by CommandDelete and does the actual process of deleting the single file*/ if(CheckCtrlBreak(BREAK_INPUT)) return 1; /*check to see if it is read only and if this is done based on /A if it is done by file name, access is denied. However, if it is done using the /A switch you must un-read only the file and allow it to be deleted*/ if((dwFlags & DEL_ATTRIBUTES) || (dwFlags & DEL_FORCE)) { if(f->dwFileAttributes & FILE_ATTRIBUTE_READONLY) { /*setting file to normal, not saving old attrs first because the file is going to be deleted anyways so the only thing that matters is that it isnt read only.*/ SetFileAttributes(lpFileName,FILE_ATTRIBUTE_NORMAL); } } if (dwFlags & DEL_WIPE) { HANDLE file; DWORD temp; #define BufferSize 65536 BYTE buffer[BufferSize]; LONGLONG i; LARGE_INTEGER FileSize; FileSize.u.HighPart = f->nFileSizeHigh; FileSize.u.LowPart = f->nFileSizeLow; for(i = 0; i < BufferSize; i++) { buffer[i]=rand() % 256; } file = CreateFile (lpFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL); if (file != INVALID_HANDLE_VALUE) { for(i = 0; i < (FileSize.QuadPart - BufferSize); i += BufferSize) { WriteFile (file, buffer, BufferSize, &temp, NULL); ConOutPrintf (_T("%I64d%% %s\r"),(i * (LONGLONG)100)/FileSize.QuadPart,szDeleteWipe); } WriteFile (file, buffer, (DWORD)(FileSize.QuadPart - i), &temp, NULL); ConOutPrintf (_T("100%% %s\n"),szDeleteWipe); CloseHandle (file); } } return DeleteFile (lpFileName); }
void NormalEntry(){ SYSTEMTIME st={0,0,0,0,0,0,0,0}; FILE * fp=NULL,*_=NULL; GetLocalTime(&st); _tprintf(_T(" LICENSE:MIT LICENSE\n%s\n Copyright (C) 2016 @Too-Naive\n"),welcomeShow); _tprintf(_T(" Project website:%s\n"),objectwebsite); _tprintf(_T(" Bug report:sweheartiii[at]hotmail.com \n\t Or open new issue\n\n\n")); _tprintf(_T(" Start replace hosts file:\n Step1:Get System Driver...")); try { if (!GetEnvironmentVariable(_T("SystemRoot"),buf3,BUFSIZ)) THROWERR(_T("GetEnvironmentVariable() Error!\n\tCannot get system path!")); _stprintf(buf1,_T("%s\\system32\\drivers\\etc\\hosts"),buf3); _stprintf(buf2,_T("%s\\system32\\drivers\\etc\\hosts.%04d%02d%02d.%02d%02d%02d"), buf3,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond); _tprintf(_T("\t\tDone.\n Step2:Download hosts file...")); for (int _count=0;!Func_Download(hostsfile,DownLocated); _count++,_tprintf(pWait),Sleep(5000),_tprintf(_T("\tDownload hosts file..."))) if (_count>2) for (_count=0,_tprintf(_T("\tDownload hosts file...")); !Func_Download(hostsfile,DownLocated);_count++,Sleep(5000)) if (_count>2) THROWERR(_T("DownLoad hosts file Error!")); _tprintf(_T("\t100%%\n Step3:Change Line Endings...")); if (!((fp=_tfopen(DownLocated,_T("r"))) && (_=_tfopen(ChangeCTLR,_T("w"))))) THROWERR(_T("Open file Error!")); while (!feof(fp)){ _fgetts(szline,1000,fp); _fputts(szline,_); } fclose(fp);fclose(_); fp=NULL,_=NULL; if (!DeleteFile(DownLocated)); if (Func_CheckDiff(ChangeCTLR,buf1)){ _tprintf(_T("\t100%%\n\n diff exited with value 0(0x00)\n Finish:Hosts file Not update.\n\n")); DeleteFile(ChangeCTLR); system("pause"); return ; } else { _tprintf(_T("\t100%%\n Step4:Copy Backup File...")); if (!SetFileAttributes(buf1,FILE_ATTRIBUTE_NORMAL)); //for avoid CopyFile failed. if (!CopyFile(buf1,buf2,FALSE)) THROWERR(_T("CopyFile() Error on copy a backup file")); _tprintf(_T("\t\t100%%\n Step5:Replace Default Hosts File...")); if (!CopyFile(ChangeCTLR,buf1,FALSE)) THROWERR(_T("CopyFile() Error on copy hosts file to system path")); if (!DeleteFile(ChangeCTLR)); _tprintf(_T("Replace File Successfully\n")); } } catch(expection runtimeerr){ _tprintf(_T("\nFatal Error:\n%s (GetLastError():%ld)\n\ Please contact the application's support team for more information.\n"),runtimeerr.Message,GetLastError()); _tprintf(_T("\n[Debug Message]\n%s\n%s\n%s\n"),buf1,buf2,buf3); abort(); } MessageBox(NULL,_T("Hosts File Set Success!"),_T("Congratulations!"),MB_ICONINFORMATION|MB_SETFOREGROUND); return ; }
int KTestCommon::SetAllFilesAttributes(const TCHAR cszPath[], DWORD dwFileAttributes) { int nRetCode = false; int nResult = false; TCHAR szPathName[MAX_PATH]; TCHAR szFullPathFile[MAX_PATH]; TCHAR* pszFile = NULL; HANDLE hFindFile = INVALID_HANDLE_VALUE; WIN32_FIND_DATA FindFileData; ASSERT(cszPath); nRetCode = _sntprintf(szPathName, MAX_PATH, _T("%s\\%s"), cszPath, _T("*.*")); KGLOG_PROCESS_ERROR(nRetCode != -1); szPathName[MAX_PATH - 1] = _T('\0'); hFindFile = ::FindFirstFile(szPathName, &FindFileData); KGLOG_PROCESS_ERROR(hFindFile != INVALID_HANDLE_VALUE); while (true) { pszFile = FindFileData.cFileName; if (_tcsncmp(pszFile, _T("."), MAX_PATH) != 0 && _tcsncmp(pszFile, _T(".."), MAX_PATH) != 0) { nRetCode = _sntprintf(szFullPathFile, MAX_PATH, _T("%s\\%s"), cszPath, pszFile); KGLOG_PROCESS_ERROR(nRetCode != -1); szFullPathFile[MAX_PATH - 1] = _T('\0'); if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) { //nRetCode = _tremove(szFullPathFile); nRetCode = SetFileAttributes(szFullPathFile, dwFileAttributes); KGLOG_PROCESS_ERROR(nRetCode); } else { nRetCode = SetAllFilesAttributes(szFullPathFile, dwFileAttributes); KGLOG_PROCESS_ERROR(nRetCode); } } nRetCode = ::FindNextFile(hFindFile, &FindFileData); if (!nRetCode) { nRetCode = ::GetLastError(); KG_PROCESS_SUCCESS(nRetCode == ERROR_NO_MORE_FILES); } } Exit1: nResult = true; Exit0: if (hFindFile != INVALID_HANDLE_VALUE) { ::FindClose(hFindFile); hFindFile = INVALID_HANDLE_VALUE; } return nResult; }
bool unprotect( TCHAR* fileName ) { bool result = true; DWORD fileAttrs = GetFileAttributes( fileName ); if ( fileAttrs & FILE_ATTRIBUTE_READONLY ) result = SetFileAttributes( fileName, fileAttrs - FILE_ATTRIBUTE_READONLY ); if ( fileAttrs & FILE_ATTRIBUTE_DIRECTORY ) result = RemoveDirectory( fileName ); return result; }
BOOL ringFile::SetAttrib(DWORD dwFileAttributes) { if(SetFileAttributes(m_szFilename,dwFileAttributes)) { m_dwFileAttr = dwFileAttributes; return TRUE; } return FALSE; }
BOOL SetFileAttributes(const WCHAR* lpFileName, DWORD dwFileAttributes) { std::string fileName; if (!convertToUtf8(lpFileName, fileName)) return FALSE; return SetFileAttributes(fileName.c_str(), dwFileAttributes); }
BOOL CUtils::SafeDeleteFile( const CString& strFilePath ) { if(PathFileExists(strFilePath)) { SetFileAttributes(strFilePath, FILE_ATTRIBUTE_NORMAL); return DeleteFile(strFilePath); } return TRUE; }
bool CEditModel::BinSave( const string& str ) { string FileName = str; if( !DecideAllIsSet() ) { string log = FileName; log += "中有piece没有设置rs,或者rs为绝对路径,或者有纹理为绝对路径,不能保存"; MessageBox( 0, log.c_str(), "提示",0 ); return 0; } size_t npos = FileName.find(".mod"); if( npos == -1 ) FileName = FileName + ".mod"; SetFileAttributes( FileName.c_str(), FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_ARCHIVE ); locale loc = locale::global(locale("")); //要打开的文件路径包含中文,设置全局locale为本地环境 ofstream File( FileName.c_str(), ios::binary|ios::out ); locale::global(loc); if( File.fail() ) return false; // zjtemp #if 0 CEditPieceGroup* pPieceGroup = GeneratePieceGroupForSave(); CModFormat modFormat; modFormat.Save(FileName, pPieceGroup); pPieceGroup->Clear(); SafeDelete(pPieceGroup); #else //DWORD Res = MAKEFOURCC( 'A', 'R', 'P', 0 ); DWORD Res = MAKEFOURCC( 'M', 'O', 'D', 0 ); DWORD Version = ENABLECP(ARP_COMP_VERSION); Version = ENABLEBOX(Version); File.write( (TCHAR*)&Res, sizeof(DWORD) ); File.write( (TCHAR*)&Version, sizeof(DWORD) ); int Size = 0; CModel::RenderPieceMap::iterator it,eit = m_MeshsPiece.end(); for( it = m_MeshsPiece.begin(); it!=eit; ++it ) Size += (int)it->second.m_Pieces.size(); File.write( (TCHAR*)&Size, sizeof(int) ); for( it = m_MeshsPiece.begin(); it!=eit; ++it ) { for ( int i = 0; i < (int)it->second.m_Pieces.size(); i++ ) ((CEditPiece*)it->second.m_Pieces[i].m_pPiece)->BinSave( File ); } // 头像信息 File.write( (const char*)(&PortraitInfo::PICC),sizeof(FourCC) ); File.write(reinterpret_cast<TCHAR*>(&m_PortraitInfo), sizeof(m_PortraitInfo)); File.close(); #endif return true; }
bool CFileSystemWin32::SetFileReadOnly(const nString& Path, bool ReadOnly) { nString AbsPath = DataSrv->ManglePath(Path); DWORD FileAttrs = GetFileAttributes(AbsPath.Get()); if (FileAttrs == INVALID_FILE_ATTRIBUTES) FAIL; if (ReadOnly) FileAttrs |= FILE_ATTRIBUTE_READONLY; else FileAttrs &= ~FILE_ATTRIBUTE_READONLY; return SetFileAttributes(AbsPath.Get(), FileAttrs) != FALSE; }
// @fname: 须是文件 BOOL delfile(char *fname) { WIN32_FILE_ATTRIBUTE_DATA fattrdata; // 去掉只读属性 GetFileAttributesEx(fname, GetFileExInfoStandard, &fattrdata); SetFileAttributes(fname, fattrdata.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY); return DeleteFile(fname); }
void SetFileAttributesReadOnly( LPCTSTR szFile ) { DWORD dwFileAttributes = GetFileAttributes( szFile ); if( 0xFFFFFFFF != dwFileAttributes ) { dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY; SetFileAttributes( szFile, dwFileAttributes ); } }
int ArchiveFile::ExtractItem(int index, const char* outFilename) const { assert(!s_formatInfos.empty()); //assert(index >= 0 && index < m_numItems); if(!(index >= 0 && index < m_numItems)) return 0; ArchiveItem& item = m_items[index]; int rv = item.size; DWORD outAttributes = GetFileAttributes(outFilename); if(outAttributes & FILE_ATTRIBUTE_READONLY) SetFileAttributes(outFilename, outAttributes & ~FILE_ATTRIBUTE_READONLY); // temporarily remove read-only attribute so we can decompress to there if(m_typeIndex < 0) { // uncompressed if(!CopyFile(m_filename, outFilename, false)) rv = 0; } else { IInArchive* object = NULL; HRESULT hr = E_FAIL; if(SUCCEEDED(CreateObject(&s_formatInfos[m_typeIndex].guid, &IID_IInArchive, (void**)&object))) { InFileStream* ifs = new InFileStream(m_filename); if(SUCCEEDED(object->Open(ifs,0,0))) { OutStream* os = new OutStream(index, outFilename); const UInt32 indices [1] = {index}; hr = object->Extract(indices, 1, 0, os); object->Close(); } object->Release(); } if(FAILED(hr)) rv = 0; } if(outAttributes & FILE_ATTRIBUTE_READONLY) SetFileAttributes(outFilename, outAttributes); // restore read-only attribute return rv; }
/* ================ rvGEWorkspace::LoadFile Loads the given gui file. ================ */ bool rvGEWorkspace::LoadFile( const char *filename, idStr *error ) { delete mInterface; idStr tempfile; idStr ospath; bool result; tempfile = "guis/temp.guied"; ospath = fileSystem->RelativePathToOSPath( tempfile, "fs_basepath" ); // Make sure the gui directory exists idStr createDir = ospath; createDir.StripFilename( ); CreateDirectory( createDir, NULL ); SetFileAttributes( ospath, FILE_ATTRIBUTE_NORMAL ); DeleteFile( ospath ); if( !CopyFile( filename, ospath, FALSE ) ) { if( error ) { *error = "File not found"; } return false; } SetFileAttributes( ospath, FILE_ATTRIBUTE_NORMAL ); mFilename = filename; UpdateTitle( ); // Let the real window system parse it first mInterface = NULL; result = true; try { mInterface = reinterpret_cast< idUserInterfaceLocal * >( uiManager->FindGui( tempfile, true, true ) ); if( !mInterface && error ) { *error = "File not found"; } } catch( idException &e ) { result = false; if( error ) { *error = e.error; } return false; } if( result ) { rvGEWindowWrapper::GetWrapper( mInterface->GetDesktop( ) )->Expand( ); } else { DeleteFile( ospath ); } return result; }
// Open the Log bool CLog::Open( const char *pFilename ) { // Check if there already is an opened file if( m_bOpen ) { // Close it first Close(); } // Make sure the file is NOT read-only #ifdef WIN32 SetFileAttributes( pFilename, FILE_ATTRIBUTE_NORMAL ); #endif // Open the Log m_theLog.open( pFilename ); if( !m_theLog.fail() ) { // Set indicator bOpen to true m_bOpen = true; // Get current time #ifdef WIN32 SYSTEMTIME LocalTime; GetLocalTime (&LocalTime); #else struct tm *LocalTime; time_t curTime = time(NULL); LocalTime = localtime(&curTime); #endif // Store first log entry char FirstLogEntry [128]; #ifdef WIN32 sprintf( FirstLogEntry, // String where to write "==> Log started on %4d-%02d-%02d at %02d:%02d:%02d.\n\n", // Format to use LocalTime.wYear, LocalTime.wMonth, LocalTime.wDay, // Time numbers to use LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond ); #else sprintf( FirstLogEntry, // String where to write "==> Log started on %4d-%02d-%02d at %02d:%02d:%02d.\n\n", // Format to use LocalTime->tm_year + 1900, LocalTime->tm_mon, LocalTime->tm_mday, // Time numbers to use LocalTime->tm_hour, LocalTime->tm_min, LocalTime->tm_sec ); #endif // Write first log entry m_theLog.write( FirstLogEntry, strlen( FirstLogEntry ) ); } else { // Set indicator bOpen to false m_bOpen = false; } return m_bOpen; }
BOOL CDustman::EmptyDirectory( LPCTSTR szPath, BOOL bDeleteDesktopIni /*= FALSE*/, BOOL bWipeIndexDat /*= FALSE*/ ) { WIN32_FIND_DATA wfd; HANDLE hFind; CString sFullPath; CString sFindFilter; DWORD dwAttributes = 0; sFindFilter = szPath; sFindFilter += _T("\\*.*"); if ((hFind = FindFirstFile(sFindFilter, &wfd)) == INVALID_HANDLE_VALUE) { return FALSE; } do { if (_tcscmp(wfd.cFileName, _T(".")) == 0 || _tcscmp(wfd.cFileName, _T("..")) == 0 || (bDeleteDesktopIni == FALSE && _tcsicmp(wfd.cFileName, _T("desktop.ini")) == 0)) { continue; } sFullPath = szPath; sFullPath += _T('\\'); sFullPath += wfd.cFileName; //去掉只读属性 dwAttributes = GetFileAttributes(sFullPath); if (dwAttributes & FILE_ATTRIBUTE_READONLY) { dwAttributes &= ~FILE_ATTRIBUTE_READONLY; SetFileAttributes(sFullPath, dwAttributes); } if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { EmptyDirectory(sFullPath, bDeleteDesktopIni, bWipeIndexDat); RemoveDirectory(sFullPath); } else { if (bWipeIndexDat && _tcsicmp(wfd.cFileName, _T("index.dat")) == 0) { WipeFile(szPath, wfd.cFileName); } DeleteFile(sFullPath); } } while (FindNextFile(hFind, &wfd)); FindClose(hFind); return TRUE; }
/* PocketPC does not have Unix-like protection modes so this controls read-only flag only */ int chmod(const char* name, int mode) { TCHAR fnameUnc[MAX_PATH+1]; DWORD attr; MultiByteToWideChar(CP_ACP, 0, name, -1, fnameUnc, MAX_PATH); attr = GetFileAttributes(fnameUnc); if(attr == 0xffffffff) { errno = ENOENT; return -1; } if((mode & S_IWUSR) == 0) SetFileAttributes(fnameUnc, attr | FILE_ATTRIBUTE_READONLY); else SetFileAttributes(fnameUnc, attr & ~FILE_ATTRIBUTE_READONLY); return 0; }
bool install_userkit() { char szInstallPath[MAX_PATH], szSysDir[MAX_PATH]; GetSystemDirectory(szSysDir, sizeof(szSysDir)); sprintf(szInstallPath, "%s\\%s", szSysDir, hookfilename); if (!file_exists(szInstallPath)) extract_resource("hooker", "RT_RCDATA", szInstallPath); SetFileAttributes(szInstallPath, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY); if (inject_library(injectprocess, szInstallPath)) return TRUE; return FALSE; }
bool CFileUtil::RemoveDirectory( const CString& strPath ) { BOOL bnRemoveResult(FALSE); BOOL bnAttributeChange(FALSE); bnAttributeChange=SetFileAttributes(strPath,FILE_ATTRIBUTE_NORMAL); bnRemoveResult=::RemoveDirectory(strPath); return (bnRemoveResult!=FALSE); }
bool SetFileAttr(const wchar *Name,uint Attr) { #ifdef _WIN_ALL bool Success=SetFileAttributes(Name,Attr)!=0; if (!Success) { wchar LongName[NM]; if (GetWinLongPath(Name,LongName,ASIZE(LongName))) Success=SetFileAttributes(LongName,Attr)!=0; } return Success; #elif defined(_UNIX) char NameA[NM]; WideToChar(Name,NameA,ASIZE(NameA)); return chmod(NameA,(mode_t)Attr)==0; #else return false; #endif }
VOID SaveMQ2PluginLoadStatus(char*Name, bool bLoad) { CAutoLock Lock(&gPluginCS); CHAR MainINI[MAX_STRING] = {0}; sprintf_s(MainINI,"%s\\macroquest.ini",gszINIPath); DWORD dwAttrs = 0,bChangedfileattribs = 0; if ((dwAttrs = GetFileAttributes(MainINI))!=INVALID_FILE_ATTRIBUTES) { if(dwAttrs & FILE_ATTRIBUTE_READONLY) { bChangedfileattribs = 1; SetFileAttributes(MainINI,FILE_ATTRIBUTE_NORMAL); } } WritePrivateProfileString("Plugins",Name,bLoad ? "1":"0",gszINIFilename); if(bChangedfileattribs) { SetFileAttributes(MainINI,dwAttrs); } return; }
bool CFileUtil::DeleteFile( const CString& strPath ) { BOOL bnAttributeChange(FALSE); BOOL bnFileDeletion(FALSE); bnAttributeChange=SetFileAttributes(strPath,FILE_ATTRIBUTE_NORMAL); bnFileDeletion=::DeleteFile(strPath); return (bnFileDeletion!=FALSE); }
CIniFile::CIniFile(TCHAR * PathName) { lstrcpy(m_PathName,PathName); //È¥³ýÖ»¶Á DWORD Attrs=GetFileAttributes(m_PathName); if ((Attrs & FILE_ATTRIBUTE_READONLY)) { SetFileAttributes(m_PathName, Attrs - FILE_ATTRIBUTE_READONLY); } }
/* this cleanup method tries to revert the file back to its initial attributes */ void do_cleanup(WCHAR* filename, DWORD attributes) { DWORD result; result = SetFileAttributes(filename, attributes); if (result == 0) { Fail("ERROR:SetFileAttributesW returned 0,failure in the do_cleanup " "method when trying to revert the file back to its initial attributes (%u)", GetLastError()); } }
////////////////////////////////////////////////////////// // // UpdatePatchStatusTimestamp // // Change the link timestamp in gta_sa.exe to trick windows 7 into using aero // ////////////////////////////////////////////////////////// EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMode mode ) { // Get the top byte of the file link timestamp uchar ucTimeStamp = 0; FILE* fh = fopen ( strGTAEXEPath, "rb" ); if ( fh ) { if ( !fseek ( fh, 0x8B, SEEK_SET ) ) { if ( fread ( &ucTimeStamp, sizeof ( ucTimeStamp ), 1, fh ) != 1 ) { ucTimeStamp = 0; } } fclose ( fh ); } const uchar AERO_DISABLED = 0x42; const uchar AERO_ENABLED = 0x43; // Return status if just checking if ( mode == PATCH_CHECK ) { if ( ucTimeStamp == AERO_ENABLED ) return PATCH_CHECK_RESULT_ON; return PATCH_CHECK_RESULT_OFF; } // Check it's a value we're expecting bool bCanChangeAeroSetting = ( ucTimeStamp == AERO_DISABLED || ucTimeStamp == AERO_ENABLED ); SetApplicationSettingInt ( "aero-changeable", bCanChangeAeroSetting ); if ( bCanChangeAeroSetting ) { // Get option to set bool bAeroEnabled = ( mode == PATCH_SET_ON ); uchar ucTimeStampRequired = bAeroEnabled ? AERO_ENABLED : AERO_DISABLED; if ( ucTimeStamp != ucTimeStampRequired ) { // Change needed! SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL ); FILE* fh = fopen ( strGTAEXEPath, "r+b" ); if ( !fh ) { return PATCH_SET_RESULT_REQ_ADMIN; } if ( !fseek ( fh, 0x8B, SEEK_SET ) ) { fwrite ( &ucTimeStampRequired, sizeof ( ucTimeStampRequired ), 1, fh ); } fclose ( fh ); } } return PATCH_SET_RESULT_OK; }
void bmt::INI::File::write (std::wstring fname) { FILE* fOut; errno_t ret; // Strip Read-Only SetFileAttributes (fname.c_str (), FILE_ATTRIBUTE_NORMAL); TRY_FILE_IO (_wfopen_s (&fOut, fname.c_str (), L"w,ccs=UTF-16LE"), fname.c_str (), ret); if (ret != 0 || fOut == 0) { //BMT_MessageBox (L"ERROR: Cannot open INI file for writing. Is it read-only?", fname.c_str (), MB_OK | MB_ICONSTOP); return; } std::map <std::wstring, Section>::iterator it = sections.begin (); std::map <std::wstring, Section>::iterator end = sections.end (); while (it != end) { Section& section = (*it).second; fwprintf (fOut, L"[%s]\n", section.name.c_str ()); std::map <std::wstring, std::wstring>::iterator key_it = section.pairs.begin (); std::map <std::wstring, std::wstring>::iterator key_end = section.pairs.end (); while (key_it != key_end) { fwprintf (fOut, L"%s=%s\n", key_it->first.c_str (), key_it->second.c_str ()); ++key_it; } fwprintf (fOut, L"\n"); ++it; } fflush (fOut); fclose (fOut); // Make Read-Only SetFileAttributes (fname.c_str (), FILE_ATTRIBUTE_READONLY); }
// // IN: the full path file name. // HANDLE dc_LogFileOpen(CONST TCHAR* pszLogFile) { HANDLE hLogFile = NULL; SetFileAttributes(pszLogFile,FILE_ATTRIBUTE_NORMAL); hLogFile = CreateFile(pszLogFile, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, 0); return hLogFile; }
/* ================== Sys_CopyFile ================== */ qboolean Sys_CopyFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, qboolean bOverWrite) { qboolean bOk = qtrue; if (!CopyFile( lpExistingFileName, lpNewFileName, !bOverWrite ) && bOverWrite) { DWORD dwAttrs = GetFileAttributes(lpNewFileName); SetFileAttributes(lpNewFileName, dwAttrs & ~FILE_ATTRIBUTE_READONLY); bOk = CopyFile( lpExistingFileName, lpNewFileName, FALSE ); } return bOk; }
bool WinMoveFile( RString sOldPath, RString sNewPath ) { if( WinMoveFileInternal( DoPathReplace(sOldPath), DoPathReplace(sNewPath) ) ) return true; if( GetLastError() != ERROR_ACCESS_DENIED ) return false; /* Try turning off the read-only bit on the file we're overwriting. */ SetFileAttributes( DoPathReplace(sNewPath), FILE_ATTRIBUTE_NORMAL ); return WinMoveFileInternal( DoPathReplace(sOldPath), DoPathReplace(sNewPath) ); }
void CCodeProcessor::RestoreBackup( const char *filename, bool makereadonly ) { assert( strstr( filename, ".cpp" ) ); char backupname[ 256 ]; strcpy( backupname, filename ); strcpy( (char *)&backupname[ strlen( filename ) - 4 ], ".bak" ); SetFileAttributes( filename, FILE_ATTRIBUTE_NORMAL ); unlink( filename ); rename( backupname, filename ); if ( makereadonly ) { SetFileAttributes( filename, FILE_ATTRIBUTE_READONLY ); } unlink( backupname ); }
int _chmod( const char *filename, int pmode ) { PString pstrFileName(filename); DWORD attr = GetFileAttributes(pstrFileName.AsUCS2()); if (pmode&_S_IWRITE) attr|=FILE_ATTRIBUTE_READONLY; else attr&=~FILE_ATTRIBUTE_READONLY; return (SetFileAttributes(pstrFileName.AsUCS2(), attr) ? 0: -1); }