static int win_CreateDir(lua_State *L) { BOOL result, opt_tolerant, opt_original; const wchar_t* path = check_utf8_string(L, 1, NULL); const char* flags = ""; if (lua_type(L,2) == LUA_TSTRING) flags = lua_tostring(L,2); else if (lua_toboolean(L,2)) flags = "t"; opt_tolerant = strchr(flags,'t') != NULL; opt_original = strchr(flags,'o') != NULL; if(dir_exist(path)) { if (opt_tolerant) return lua_pushboolean(L,1), 1; return lua_pushnil(L), lua_pushliteral(L, "directory already exists"), 2; } result = opt_original ? CreateDirectoryW(path,NULL) : mkdir(path); if(result) return lua_pushboolean(L, 1), 1; return SysErrorReturn(L); }
Error DirAccessWindows::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); if (p_dir.is_rel_path()) p_dir = current_dir.plus_file(p_dir); p_dir = p_dir.replace("/", "\\"); bool success; int err; p_dir = "\\\\?\\" + p_dir; //done according to // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx success = CreateDirectoryW(p_dir.c_str(), NULL); err = GetLastError(); if (success) { return OK; }; if (err == ERROR_ALREADY_EXISTS || err == ERROR_ACCESS_DENIED) { return ERR_ALREADY_EXISTS; }; return ERR_CANT_CREATE; }
BOOL __lib_CreateDirectoryW( LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ) /***********************************************************************/ { if( WIN32_IS_NT ) { /* NT */ return( CreateDirectoryW( lpPathName, lpSecurityAttributes ) ); } else { /* Win95 or Win32s */ char * mbPathName; BOOL osrc; size_t cvt; size_t len; /*** Allocate some memory ***/ len = wcslen( lpPathName ) * MB_CUR_MAX + 1; mbPathName = lib_malloc( len ); if( mbPathName == NULL ) { return( FALSE ); } /*** Prepare to call the OS ***/ cvt = wcstombs( mbPathName, lpPathName, len ); if( cvt == (size_t)-1 ) { lib_free( mbPathName ); return( FALSE ); } /*** Call the OS ***/ osrc = CreateDirectoryA( mbPathName, lpSecurityAttributes ); lib_free( mbPathName ); return( osrc ); } }
/** * Obtains the updater path alongside a subdir of the service binary. * The purpose of this function is to return a path that is likely high * integrity and therefore more safe to execute code from. * * @param serviceUpdaterPath Out parameter for the path where the updater * should be copied to. * @return TRUE if a file path was obtained. */ BOOL GetSecureUpdaterPath(WCHAR serviceUpdaterPath[MAX_PATH + 1]) { if (!GetModuleFileNameW(NULL, serviceUpdaterPath, MAX_PATH)) { LOG_WARN(("Could not obtain module filename when attempting to " "use a secure updater path. (%d)", GetLastError())); return FALSE; } if (!PathRemoveFileSpecW(serviceUpdaterPath)) { LOG_WARN(("Couldn't remove file spec when attempting to use a secure " "updater path. (%d)", GetLastError())); return FALSE; } if (!PathAppendSafe(serviceUpdaterPath, L"update")) { LOG_WARN(("Couldn't append file spec when attempting to use a secure " "updater path. (%d)", GetLastError())); return FALSE; } CreateDirectoryW(serviceUpdaterPath, NULL); if (!PathAppendSafe(serviceUpdaterPath, L"updater.exe")) { LOG_WARN(("Couldn't append file spec when attempting to use a secure " "updater path. (%d)", GetLastError())); return FALSE; } return TRUE; }
bool ServiceUpdate(bool validService) { if (validService) { ServiceInstaller si; if (si.run() != 0) return false; } else { std::wstring appPath = UTIL::OS::getCommonProgramFilesPath(); if (!FolderExists(appPath.c_str())) CreateDirectoryW(appPath.c_str(), NULL); std::wstring newService = UTIL::OS::getCommonProgramFilesPath(L"desura_service.exe"); std::wstring curService = UTIL::OS::getCurrentDir(L"desura_service.exe"); char regname[255]; Safe::snprintf(regname, 255, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\%s\\ImagePath", SERVICE_NAME); CopyFileW(curService.c_str(), newService.c_str(), FALSE); UTIL::WIN::setRegValue(regname, gcString(newService).c_str()); } return true; }
/* Open the log file * TODO: format like standard apache error.log * Add the EventLogger */ HANDLE apxLogOpen( APXHANDLE hPool, LPCWSTR szPath, LPCWSTR szPrefix) { WCHAR sPath[MAX_PATH+1]; WCHAR sName[MAX_PATH+1]; SYSTEMTIME sysTime; apx_logfile_st *h; GetLocalTime(&sysTime); if (!szPath) { if (GetSystemDirectoryW(sPath, MAX_PATH) == 0) return INVALID_HANDLE_VALUE; lstrcatW(sPath, L"\\LogFiles\\"); if (!szPrefix) lstrcatW(sPath, L"Apache"); else lstrcatW(sPath, szPrefix); wsprintfW(sName, L"\\%04d%02d%02d.log", sysTime.wYear, sysTime.wMonth, sysTime.wDay); } else { lstrcpyW(sPath, szPath); if (szPrefix) wsprintfW(sName, L"\\%s", szPrefix); else wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log", sysTime.wYear, sysTime.wMonth, sysTime.wDay); } if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st)))) return NULL; /* Set default level to info */ h->dwLogLevel = APXLOG_LEVEL_INFO; CreateDirectoryW(sPath, NULL); h->sysTime = sysTime; lstrcpyW(h->szPath, sPath); lstrcatW(sPath, sName); if (szPrefix) lstrcpyW(h->szPrefix, szPrefix); h->hFile = CreateFileW(sPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL); /* Set this file as system log file */ if (!_st_sys_loghandle) _st_sys_loghandle = h; return (HANDLE)h; }
bool DirectoryInfo::CreateDirectoryA(LPCSTR dirName) { WCHAR dirNameW[MAX_PATH]; if( NULL!=dirName ) { THROW_LASTERROREXCEPTION1( ::MultiByteToWideChar( CP_ACP, 0, dirName, -1,dirNameW, MAX_PATH) ); } return dirName!=NULL ? CreateDirectoryW(dirNameW) : false;; } // of DirectoryInfo::CreateDirectoryW()
static int do_CreateDirectory(int argc, wchar_t **argv) { if (argc != 3) fail("usage: CreateDirectory PathName 0"); BOOL r = CreateDirectoryW(argv[1], 0); errprint(r); return 0; }
BOOL XCEAPI XCECreateDirectoryW(const wchar_t *oldpath, LPSECURITY_ATTRIBUTES lpSec) { wchar_t newpath[MAX_PATH]; XCEFixPathW(oldpath, newpath); return CreateDirectoryW(newpath, lpSec); }
BOOL My_CreateDirectoryW() { LPCWSTR lpPathName=NULL; LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL; BOOL returnVal_Real = NULL; BOOL returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; disableInterception(); returnVal_Real = CreateDirectoryW (lpPathName,lpSecurityAttributes); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = CreateDirectoryW (lpPathName,lpSecurityAttributes); error_Intercepted = GetLastError(); return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
UBOOL FFileManagerWindows::InternalMakeDirectory( const TCHAR* Path, UBOOL Tree ) { if( Tree ) { return FFileManagerGeneric::MakeDirectory( Path, Tree ); } return CreateDirectoryW(Path,NULL)!=0 || GetLastError()==ERROR_ALREADY_EXISTS; }
static BOOL msi_create_directory( MSIPACKAGE *package, const WCHAR *path ) { BOOL ret; msi_disable_fs_redirection( package ); ret = CreateDirectoryW( path, NULL ); msi_revert_fs_redirection( package ); return ret; }
static int mkdir_parent(const wchar_t *path) { // Copy the path to a temporary buffer. wchar_t buffer[4096]; size_t buflen = wcslen(path); if (buflen + 1 >= _countof(buffer)) { return 0; } wcscpy_s(buffer, _countof(buffer), path); // Seek back to find the last path separator. while (buflen-- > 0) { if (buffer[buflen] == '/' || buffer[buflen] == '\\') { buffer[buflen] = 0; break; } } if (buflen == (size_t)-1 || buflen == 0) { // There was no path separator, or this was the root directory. return 0; } if (CreateDirectoryW(buffer, NULL) != 0) { // Success! return 1; } // Failed. DWORD last_error = GetLastError(); if (last_error == ERROR_ALREADY_EXISTS) { // Not really an error: the directory is already there. return 1; } if (last_error == ERROR_PATH_NOT_FOUND) { // We need to make the parent directory first. if (mkdir_parent(buffer)) { // Parent successfully created. Try again to make the child. if (CreateDirectoryW(buffer, NULL) != 0) { // Got it! return 1; } } } return 0; }
// File IO ///////////////////////////////////////////////////// Bool System::CreateDirectory( const GChar * strPathName ) const { #if ( defined(UNICODE) || defined (_UNICODE) ) BOOL bRes = CreateDirectoryW( strPathName, NULL ); #else BOOL bRes = CreateDirectoryA( strPathName, NULL ); #endif return ( bRes != FALSE ); }
posix_errno_t efile_make_dir(const efile_path_t *path) { ASSERT_PATH_FORMAT(path); if(!CreateDirectoryW((WCHAR*)path->data, NULL)) { return windows_to_posix_errno(GetLastError()); } return 0; }
bool os_link_symbolic_junctions(const std::wstring &target, const std::wstring &lname) { bool ret=false; std::wstring wtarget=target; HANDLE hJunc=INVALID_HANDLE_VALUE; char *buf=NULL; if(wtarget.find(os_file_prefix(L""))==0) wtarget.erase(0, os_file_prefix(L"").size()); if(!wtarget.empty() && wtarget[0]!='\\') wtarget=L"\\??\\"+wtarget; if(!wtarget.empty() && wtarget[target.size()-1]!='\\') wtarget+=L"\\"; if(!CreateDirectoryW(lname.c_str(), NULL) ) { goto cleanup; } hJunc=CreateFileW(lname.c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL); if(hJunc==INVALID_HANDLE_VALUE) goto cleanup; size_t bsize=sizeof(REPARSE_MOUNTPOINT_DATA_BUFFER) + (wtarget.size()+1) * sizeof(wchar_t)+30; buf=new char[bsize]; memset(buf, 0, bsize); REPARSE_MOUNTPOINT_DATA_BUFFER *rb=(REPARSE_MOUNTPOINT_DATA_BUFFER*)buf; rb->ReparseTag=IO_REPARSE_TAG_MOUNT_POINT; rb->ReparseTargetMaximumLength=(WORD)((wtarget.size()+1)*sizeof(wchar_t)); rb->ReparseTargetLength=rb->ReparseTargetMaximumLength-1*sizeof(wchar_t); rb->ReparseDataLength=rb->ReparseTargetLength+12; memcpy(rb->ReparseTarget, wtarget.c_str(), rb->ReparseTargetMaximumLength); DWORD bytes_ret; if(!DeviceIoControl(hJunc, FSCTL_SET_REPARSE_POINT, rb, rb->ReparseDataLength+REPARSE_MOUNTPOINT_HEADER_SIZE, NULL, 0, &bytes_ret, NULL) ) { goto cleanup; } ret=true; cleanup: if(!ret) { #ifndef OS_FUNC_NO_SERVER Server->Log("Creating junction failed. Last error="+nconvert((int)GetLastError()), LL_ERROR); #endif } delete []buf; if(hJunc!=INVALID_HANDLE_VALUE) CloseHandle(hJunc); if(!ret) { RemoveDirectoryW(lname.c_str()); } return ret; }
bool LogMgr::Initialize() { CreateDirectoryW(L"Log", NULL); for(int i = 0; i < LC_Max; i++) { ahLog[i] = CreateFileA(aLogName[i], GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE , NULL); } //fopen_s(&afpLog[i], aLogName[i], "wt"); return true; }
static void AppendPathComponent(std::wstring& value, const wchar_t* component) { value += component; if (GetFileAttributes(value.c_str()) == INVALID_FILE_ATTRIBUTES) { CreateDirectoryW(value.c_str(), nullptr); } }
int _wmkdir(const wchar_t *dirname) { if(!CreateDirectoryW(dirname, NULL)) { errno = GetLastError(); return -1; } return 0; }
int file_mkdir(const char *dir) { wchar_t wdir[MAX_PATH]; MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH); if (!CreateDirectoryW(wdir, NULL)) return -1; return 0; }
CAMLprim value win_mkdir(value path, value wpath) { CAMLparam2(path, wpath); if (!CreateDirectoryW((LPWSTR)String_val(wpath), NULL)) { win32_maperr (GetLastError ()); uerror("mkdir", path); } CAMLreturn (Val_unit); }
RTDECL(int) RTDirCreate(const char *pszPath, RTFMODE fMode, uint32_t fCreate) { /* * Validate the file mode. */ int rc; fMode = rtFsModeNormalize(fMode, pszPath, 0); if (rtFsModeIsValidPermissions(fMode)) { /* * Convert to UTF-16. */ PRTUTF16 pwszString; rc = RTStrToUtf16(pszPath, &pwszString); AssertRC(rc); if (RT_SUCCESS(rc)) { /* * Create the directory. */ if (CreateDirectoryW((LPCWSTR)pwszString, NULL)) rc = VINF_SUCCESS; else rc = RTErrConvertFromWin32(GetLastError()); /* * Turn off indexing of directory through Windows Indexing Service */ /** @todo This FILE_ATTRIBUTE_NOT_CONTENT_INDEXED hack (for .VDI files, * really) may cause failures on samba shares. That really sweet and * need to be addressed differently. We shouldn't be doing this * unless the caller actually asks for it, must less returning failure, * for crying out loud! This is only important a couple of places in * main, if important is the right way to put it... */ if ( RT_SUCCESS(rc) && !(fCreate & RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET)) { if ( SetFileAttributesW((LPCWSTR)pwszString, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) || (fCreate & RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_NOT_CRITICAL) ) rc = VINF_SUCCESS; else rc = RTErrConvertFromWin32(GetLastError()); } RTUtf16Free(pwszString); } } else { AssertMsgFailed(("Invalid file mode! %RTfmode\n", fMode)); rc = VERR_INVALID_FMODE; } LogFlow(("RTDirCreate(%p:{%s}, %RTfmode): returns %Rrc\n", pszPath, pszPath, fMode, rc)); return rc; }
bool FileImpl::createDirectoryImpl() { poco_assert (!_path.empty()); if (existsImpl() && isDirectoryImpl()) return false; if (CreateDirectoryW(_upath.c_str(), 0) == 0) handleLastErrorImpl(_path); return true; }
int __PHYSFS_platformMkDir(const char *path) { WCHAR *wpath; DWORD rc; UTF8_TO_UNICODE_STACK_MACRO(wpath, path); rc = CreateDirectoryW(wpath, NULL); __PHYSFS_smallFree(wpath); BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0); return 1; } /* __PHYSFS_platformMkDir */
// create sub directories void MetaLauncher::createMenuDirs(wchar_t *menuPath) { wchar_t *p; p = menuPath; while ((p = wcschr(p + 1, L'\\')) != NULL) { *p = L'\0'; CreateDirectoryW(menuPath, NULL); *p = L'\\'; } }
BOOL My_CreateDirectoryW() { LPCWSTR lpPathName=NULL; LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL; BOOL returnVal_Real = NULL; BOOL returnVal_Intercepted = NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); returnVal_Real = CreateDirectoryW (lpPathName,lpSecurityAttributes); error_Real = GetLastError(); enableInterception(); returnVal_Intercepted = CreateDirectoryW (lpPathName,lpSecurityAttributes); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted)); }
int _mkdir(const char* dir) { static wchar_t wdir[MAX_PATH]; BOOL rc; // wchar_t* wdir = wce_AToW(dir); wce_AToW2(dir, wdir); rc = CreateDirectoryW(wdir, NULL); return rc==0 ? -1 : 0 ; }
static VOID CreateTempDir( IN LPCWSTR VarName) { WCHAR szTempDir[MAX_PATH]; WCHAR szBuffer[MAX_PATH]; DWORD dwLength; HKEY hKey; if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { FatalError("Error: %lu\n", GetLastError()); return; } /* Get temp dir */ dwLength = MAX_PATH * sizeof(WCHAR); if (RegQueryValueExW(hKey, VarName, NULL, NULL, (LPBYTE)szBuffer, &dwLength) != ERROR_SUCCESS) { FatalError("Error: %lu\n", GetLastError()); goto cleanup; } /* Expand it */ if (!ExpandEnvironmentStringsW(szBuffer, szTempDir, MAX_PATH)) { FatalError("Error: %lu\n", GetLastError()); goto cleanup; } /* Create profiles directory */ if (!CreateDirectoryW(szTempDir, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { FatalError("Error: %lu\n", GetLastError()); goto cleanup; } } cleanup: RegCloseKey(hKey); }
bool CLoggingImp::InitLogging() { if (!SHGetSpecialFolderPathW(0, m_wszLogDir, CSIDL_APPDATA, TRUE)) { return false; } PathAppendW(m_wszLogDir, L"Logging"); if (!CreateDirectoryW(m_wszLogDir, 0) && GetLastError() != ERROR_ALREADY_EXISTS) { return false; } CleanOldLog(); wchar_t wszBaseName[MAX_PATH] = {0}; if (!GetModuleFileNameW(0, wszBaseName, MAX_PATH)) { return false; } PathRemoveExtensionW(wszBaseName); PathStripPathW(wszBaseName); wchar_t wszLogFile[MAX_PATH] = {0}; HRESULT hr = StringCchPrintfW(wszLogFile, MAX_PATH, L"%s\\%s_PID%d_%d.log", m_wszLogDir, wszBaseName, GetCurrentProcessId(), GetTickCount()); if (FAILED(hr)) { return false; } //create file std::locale loc(""); m_logwfstream.imbue(loc); m_logwfstream.open(wszLogFile, std::ios_base::out); //TODO: what mode? if (!m_logwfstream) { return false; } //initialize critical section bool bOk = true; try { InitializeCriticalSection(&m_csWriteFile); } catch (...) { bOk = false; m_logwfstream.close(); } m_logwfstream << L"\t\tIF ANY ERROR OCCURRED, " L"PLS CONTACT ME: [email protected].\n\n\n"; return bOk; }
void FileManager::Initialize() { m_moduleFileName.resize(MAX_PATH); m_moduleFileName.resize(GetModuleFileNameW( sEngine.GetInstance(), &m_moduleFileName[0], MAX_PATH)); auto filePathEnd = m_moduleFileName.find_last_of(L'\\'); m_moduleDirectory = m_moduleFileName.substr(0, filePathEnd); m_logsDirectory = m_moduleDirectory + L"\\logs"; m_scriptsDirectory = m_moduleDirectory + L"\\scripts"; CreateDirectoryW(m_logsDirectory.c_str(), nullptr); }