Пример #1
0
	//--------------------------------
	bool Utils::directoryExists( const WideString &pathString )
	{
		bool pathExists = false;

#ifdef COLLADABU_OS_WIN
		SystemType type = getSystemType();
		if( type != WINDOWS )
			return false;

		const wchar_t* currentPath = _wgetcwd( 0, 0);
		const wchar_t* testPath = pathString.c_str();

		pathExists = _wchdir( testPath ) == 0;
		_wchdir( currentPath );
		return pathExists;
#else
		SystemType type = getSystemType();
		if( type != POSIX )
			return false;

		//...
#endif

		return pathExists;
	}
Пример #2
0
bool mmOperatingSystem::IsExistingDir(mmString p_sDirName)
{
	bool v_bRes = false;

	// pobieram aktywny dysk i œcie¿kê
	int v_iDriveNo = _getdrive();
	wchar_t* v_pcCurDir = _wgetcwd(NULL,_MAX_PATH);
	if(v_pcCurDir == NULL)
	{
		throw mmError(mmeBadAlloc);
	};

	// prubujê przejœæ do œcie¿ki p_sDirName
	if(_wchdir(p_sDirName.c_str()) == 0)
	{
		v_bRes = true;
	};

	// przywracam poprzedni dysk i œcie¿kê
	_chdrive(v_iDriveNo);
	if(_wchdir(v_pcCurDir) != 0)
	{
		throw mmError(mmeUnknownError);
	};

	// zwalniam pamiêæ przydzielon¹ przez getcwd
	free(v_pcCurDir);

	return v_bRes;
}
Пример #3
0
bool CZipArchive::DirectoryExists(LPCTSTR lpszDir)
{
	TCHAR curPath[512];   /* Get the current working directory: */
	if (!_wgetcwd(curPath, 512))
		return false;
	if (_wchdir(lpszDir))	// retruns 0 if error
		return false;
	_wchdir(curPath);
	return true;
}
Пример #4
0
CAMLprim value unix_chdirW(value path)
{
  int ret;
  ret = _wchdir((LPCWSTR)String_val(path));
  if (ret == -1) uerror("chdir", path);
  return Val_unit;
}
Пример #5
0
/*----------------------------------------------------------------------*
                             rtp_wfile_setcwd
 *----------------------------------------------------------------------*/
int rtp_wfile_setcwd (unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    name = _rtp_unicode_name_to_winname (name);

    if (_wchdir ((const unsigned short *)name) != 0)
    {
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_setcwd: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }
    return (0);
#endif
	return (-1);
}
Пример #6
0
int S_windows_chdir(const char *pathname) {
  wchar_t wpathname[PATH_MAX];
  if (MultiByteToWideChar(CP_UTF8,0,pathname,-1,wpathname,PATH_MAX) == 0)
    return _chdir(pathname);
  else
    return _wchdir(wpathname);
}
Пример #7
0
//! Changes the current Working Directory to the given string.
bool CFileSystem::changeWorkingDirectoryTo(const io::path& newDirectory)
{
	bool success=false;

	if (FileSystemType != FILESYSTEM_NATIVE)
	{
		WorkingDirectory[FILESYSTEM_VIRTUAL].append(newDirectory);
		flattenFilename(WorkingDirectory[FILESYSTEM_VIRTUAL], "");
		success = 1;
	}
	else
	{
		WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;

#if defined(_IRR_WINDOWS_CE_PLATFORM_)
		success = true;
#elif defined(_MSC_VER)
	#if defined(_IRR_WCHAR_FILESYSTEM)
		success=(_wchdir(newDirectory.c_str()) == 0);
	#else
		success=(_chdir(newDirectory.c_str()) == 0);
	#endif
#else
		success=(chdir(newDirectory.c_str()) == 0);
#endif
	}

	return success;
}
Пример #8
0
posix_errno_t efile_set_cwd(const efile_path_t *path) {
    const WCHAR *path_start;

    ASSERT_PATH_FORMAT(path);

    /* We have to use _wchdir since that's the only function that updates the
     * per-drive working directory, but it naively assumes that all paths
     * starting with \\ are UNC paths, so we have to skip the long-path prefix.
     *
     * _wchdir doesn't handle long-prefixed UNC paths either so we hand those
     * to SetCurrentDirectoryW instead. The per-drive working directory is
     * irrelevant for such paths anyway. */

    if(!IS_LONG_UNC_PATH(PATH_LENGTH(path), path->data)) {
        path_start = (WCHAR*)path->data + LP_PREFIX_LENGTH;

        if(_wchdir(path_start)) {
            return windows_to_posix_errno(GetLastError());
        }
    } else {
        if(!SetCurrentDirectoryW((WCHAR*)path->data)) {
            return windows_to_posix_errno(GetLastError());
        }
    }

    return 0;
}
Пример #9
0
/****************************************************************************
 * Application::setCurrentWorkingDirectory()
 ****************************************************************************
 * This function gets the IrrlichtDevice pointed to in the globals, and
 * changes the current working directory of its FileSystem to the directory
 * in which the executable file of the program is located.
 ****************************************************************************/
void Application::setCurrentWorkingDirectory() const
{
	// TODO: Find solutions to this for other platforms
#ifdef _MSC_VER
	int pathLen;
	int bufferLen = MAX_PATH;
	DWORD lastError = 0;
	wchar_t *pathBuffer = NULL;

	do
	{
		// Create a buffer for the program directory
		pathBuffer = new wchar_t[bufferLen + 1];
		memset(pathBuffer, '\0', sizeof(wchar_t) * (bufferLen + 1));

		// Put the full path + executable filename into the buffer
		pathLen = GetModuleFileNameW(NULL, pathBuffer, bufferLen);

		// Check if an error occurred
		lastError = GetLastError();

		if (lastError == ERROR_INSUFFICIENT_BUFFER)
		{
			// Free memory allocated for the buffer
			delete [] pathBuffer;
			pathBuffer = NULL;

			// Double the size of the buffer
			bufferLen *= 2;
		}
	}
	// Keep trying until GetModuleFileNameW() is successful
	while (lastError == ERROR_INSUFFICIENT_BUFFER);

	if (pathBuffer)
	{
		/* Backtrack from the end of the buffer, truncating off one character
		 * at a time, until the start of the filename is found, so that we are
		 * left with only the program path */
		for (int i = pathLen - 1; i >= 0; --i)
		{
			if (pathBuffer[i] == L'\\' || pathBuffer[i] == L'/')
				break;
			pathBuffer[i] = L'\0';
		}

		// Change working directory to point to this directory.
#ifdef _MSC_VER
		// Visual Studio uses _wchdir() from direct.h
		_wchdir(pathBuffer);
#else
		// Other platforms use wcs_chdir() from unistd.h
		wcs_chdir(pathBuffer);
#endif

		// Free memory allocated for the buffer
		delete [] pathBuffer;
	}
#endif
}
Пример #10
0
/**
 * g_chdir:
 * @path: a pathname in the GLib file name encoding (UTF-8 on Windows)
 *
 * A wrapper for the POSIX chdir() function. The function changes the
 * current directory of the process to @path.
 *
 * See your C library manual for more details about chdir().
 *
 * Returns: 0 on success, -1 if an error occurred.
 *
 * Since: 2.8
 */
int
g_chdir (const gchar *path)
{
#ifdef G_OS_WIN32
    wchar_t *wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;

    if (wpath == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    retval = _wchdir (wpath);
    save_errno = errno;

    g_free (wpath);

    errno = save_errno;
    return retval;
#else
    return chdir (path);
#endif
}
Пример #11
0
void CPtnZler::OnMenuPattern()
{
	if (!IsBoardLegal())
	{
		window->MessageBox(L"盘面不合法", L"定形局", MB_ICONWARNING | MB_OK);
		return;
	}
	if (window->MessageBox(L"确定以当前盘面进行创作?", L"定形局", MB_ICONQUESTION | MB_OKCANCEL) != IDOK)
		return;

	g_pGameTable->SetZlerBase(this);
	g_pGameTable->SetAction(0);

	//进入Pattern目录
	TCHAR wcsPatternPath[_MAX_PATH];
	wsprintf(wcsPatternPath, L"%s\\Pattern", ModulePath);
	if (_waccess(wcsPatternPath, 0) == -1)
		_wmkdir(wcsPatternPath);
	_wchdir(wcsPatternPath);
	//创建文件夹
	time_t t = time(NULL);
	wcsftime(m_wcsTimeFolder, sizeof(m_wcsTimeFolder) / sizeof(TCHAR), L"%Y%m%d_%H%M%S", localtime(&t)); //Eg: 20130814_210517
	_wmkdir(m_wcsTimeFolder);
	//设置起始文件号
	m_nFileNumber = 1;
	if (!SavePtnTitle(wcsPatternPath))
		return;

	InitSwapRemain();
	ProcessPattern(true);
}
Пример #12
0
S32 btmtk_goep_fs_findend(void *ptr) {
    bt_ftp_find_struct *pfind;
    pfind = (bt_ftp_find_struct *) ptr;

#if defined(BTMTK_ON_WISE)
    if( NULL != pfind ) {
        FS_FindClose( (FS_HANDLE) pfind->hFile);
        pfind->hFile = 0;
        free_ctrl_buffer( pfind );
    }
#endif

#ifdef BTMTK_GOEP_USE_WIN32_FS
    _findclose(pfind->hFile);
    _wchdir( (const U16 *) g_oldcwd );
    if( NULL !=  ptr )
        free( ptr );
#endif

#ifdef BTMTK_ON_LINUX
    closedir(g_opened_dir);
#endif

    return EXT_FS_OK;
}
Пример #13
0
	//--------------------------------
	bool Utils::directoryExists( const WideString &pathString )
	{
		bool pathExists = false;


		SystemType type = getSystemType();
		if( type != WINDOWS )
			return false;

		const wchar_t* currentPath = _wgetcwd( 0, 0);
		const wchar_t* testPath = pathString.c_str();

		pathExists = _wchdir( testPath ) == 0;
		_wchdir( currentPath );
		return pathExists;

	}
Пример #14
0
int change_dir(const char* name)
{
	WCHAR wszPath[MAX_PATH+1];

    if (!MultiByteToWideChar(CP_UTF8,0,name,-1,wszPath,sizeof wszPath/sizeof *wszPath)) return 0;

	return _wchdir(wszPath);
}
Пример #15
0
int SharedUtil::File::Chdir(const char* szPath)
{
#ifdef WIN32
    return _wchdir(FromUTF8(szPath));
#else
    return chdir(szPath);
#endif
}
Пример #16
0
int p_chdir(const char* path)
{
	wchar_t* buf = gitwin_to_utf16(path);
	int ret = _wchdir(buf);

	git__free(buf);
	return ret;
}
Пример #17
0
void CBaseScriptApp::ChangeCurPathToRes()
{
#ifdef _WIN32
	_wchdir(m_pResPathMgr->GetCurPath());
#else
	chdir( utf16_to_utf8(m_pResPathMgr->GetCurPath()).c_str() );
#endif
}
Пример #18
0
int
efile_chdir(Efile_error* errInfo,	/* Where to return error codes. */
	    char* name)			/* Name of directory to make current. */
{
    int success = check_error(_wchdir((WCHAR *) name), errInfo);
    if (!success && errInfo->posix_errno == EINVAL)
	/* POSIXification of errno */
	errInfo->posix_errno = ENOENT;
    return success;
}
Пример #19
0
bool fsEnsureDirectoryExists(const wchar_t* dir) {
	if (dir == NULL) return false;
	wchar_t* targetDir = fsAbsolutePath(dir);
	wchar_t* currentDir = _wgetcwd(NULL, CBUF_TRY_SIZE);

	/// If the directory already exists, do nothing.
	if (_wchdir(targetDir) == 0) {
		_wchdir(currentDir);
		free(currentDir);
		return true;
	}

	/**
	 * Create all directories along the specified path.
	 */
	wchar_t* workPath = newWCString(wcslen(dir));
	wcscpy(workPath, dir);

	/**
	 * The first component of the path is the drive specifier.
	 * We should go to its root first.
	 */
	wchar_t* pathComponent = wcstok(workPath, L"\\");
	wchar_t* initialPath = wcsAppend(pathComponent, L"\\");
	_wchdir(initialPath);
	free(initialPath);
	pathComponent = wcstok(NULL, L"\\");

	bool status = 0;
	while (pathComponent) {
		_wmkdir(pathComponent);
		status = _wchdir(pathComponent);
		if (status != 0) break;
		pathComponent = wcstok(NULL, L"\\");
	}

	_wchdir(currentDir);
	free(currentDir);
	free(workPath);

	return status == 0;
}
Пример #20
0
/** Sets the path of the current working directory. Returns true if this was successful. */
bool Path_SetWorkingDirectory(const std::string& sPath)
{
	bool bSuccess;
#if defined( _WIN32 )
	std::wstring wsPath = UTF8to16(sPath.c_str());
	bSuccess = 0 == _wchdir(wsPath.c_str());
#else
	bSuccess = 0 == chdir(sPath.c_str());
#endif
	return bSuccess;
}
Пример #21
0
	//--------------------------------
	bool Utils::createDirectoryRecursive( const WideString &pathString )
	{
		if (pathString.length() == 0)
			return false;

		WideString path = pathString;

		if (path[path.length()-1] != '/' && path[path.length()-1] != '\\')
			path.push_back('\\');

		std::list<WideString> paths;
		size_t offset = WideString::npos;
		while ((offset != 0) && (offset = pathString.find_last_of(L"/\\", offset)) != WideString::npos)
		{
			paths.push_front(pathString.substr(0, offset + 1));
			if (offset != 0) --offset;
		}

		bool pathExists = true;
		const wchar_t* currentPath = _wgetcwd(0, 0);

		for (std::list<WideString>::const_iterator iPath = paths.begin(); iPath != paths.end(); ++iPath)
		{
			// if path exists
			if (_wchdir((*iPath).c_str()) == 0)
				continue;

			// path does not exist, try to create it
			_wmkdir((*iPath).c_str());
			
			if (_wchdir((*iPath).c_str()) != 0)
			{
				pathExists = false;
				break;
			}
		}

		// Restore current path
		_wchdir(currentPath);
		return pathExists;
	}
Пример #22
0
bool stupid_set_current_work_directory(const std::string & dirname)
{
#ifdef _MSC_VER
    std::string platform_dirname(dirname);
    stupid_directory_format(platform_dirname);
    return(0 == _wchdir(utf8_to_unicode(platform_dirname).c_str()));
#else
    std::string platform_dirname(dirname);
    stupid_directory_format(platform_dirname);
    return(0 == chdir(utf8_to_ansi(platform_dirname).c_str()));
#endif // _MSC_VER
}
Пример #23
0
void change_dir(std::string dir)
{
	#ifdef _WIN32
		wchar_t* wdir = new wchar_t[strlen(dir.c_str()) + 1];
		mbstowcs(wdir, dir.c_str(), strlen(dir.c_str()) + 1);
		_wchdir(wdir);
		//SetCurrentDirectory(wdir);
	#else
		
	#endif
	
}
Пример #24
0
void CTraceZler::SaveToFile()
{
	TCHAR wcsTraceFolder[_MAX_PATH];
	wsprintf(wcsTraceFolder, L"%s\\Trace", ModulePath);
	//进入Trace目录
	if (_wchdir(wcsTraceFolder) != 0)
	{
		_wmkdir(wcsTraceFolder);
		_wchdir(wcsTraceFolder);
	}
	//写入序号文件
	static TCHAR wcsFileName[_MAX_PATH];
	for (int i = 0; i < TrCount2; i++)
	{
		UpdateBoard(&TrList1[TrList2[i].index]);
		UpdateBoard(&TrList2[i]);
		wsprintf(wcsFileName, L"%d_%d.pgn", m_nTraceTimes, i);
		SaveToPgn(wcsFileName);
		//还原盘面
		RestoreBoard(&TrList2[i]);
		RestoreBoard(&TrList1[TrList2[i].index]);
	}
}
Пример #25
0
int eof_chdir(const char * dir)
{
	#ifdef ALLEGRO_WINDOWS
		wchar_t wdir[1024] = {0};

		if(dir == NULL)
			return -1;
		(void) uconvert(dir, U_UTF8, (char *)(&wdir[0]), U_UNICODE, 2048);
		return _wchdir(wdir);
	#else
		if(dir == NULL)
			return -1;
		return chdir(dir);
	#endif
}
Пример #26
0
posix_errno_t efile_set_cwd(const efile_path_t *path) {
    const WCHAR *path_start;

    ASSERT_PATH_FORMAT(path);

    /* We have to use _wchdir since that's the only function that updates the
     * per-drive working directory, but it naively assumes that all paths
     * starting with \\ are UNC paths, so we have to skip the \\?\-prefix. */
    path_start = (WCHAR*)path->data + LP_PREFIX_LENGTH;

    if(_wchdir(path_start)) {
        return windows_to_posix_errno(GetLastError());
    }

    return 0;
}
Пример #27
0
/*
 * Wrapper for chdir library function
 */
int
platform_chdir(const char *dir)
{
#ifdef HAVE_CHDIR
#ifdef _WIN32
    int res;
    struct gc_arena gc = gc_new();
    res = _wchdir(wide_string(dir, &gc));
    gc_free(&gc);
    return res;
#else  /* ifdef _WIN32 */
    return chdir(dir);
#endif
#else  /* ifdef HAVE_CHDIR */
    return -1;
#endif
}
Пример #28
0
	bool setCurrentDirectory(FileLocalization fileLocalization, const char* filepath)
	{
#if defined(USES_WINDOWS8_DESKTOP) || defined(USES_WINDOWS_OPENGL)
		std::wstring fullfilepath = getFullPathUnicode(fileLocalization, filepath);
		return _wchdir(fullfilepath.c_str()) == 0;
#elif defined(USES_WINDOWS8_METRO)
		Assert(false);
		return L"";
		/*Windows::Storage::StorageFolder^ folder = getStorageFolder(fileLocalization);
		std::wstring fullpath = Utils::platformStringToWString(folder->Path) + L"\\" + Utils::convertStringToWString(filepath);
		return SetCurrentDirectoryW(fullpath.c_str());*/
#elif defined(USES_LINUX)
		std::wstring fullfilepath = getFullPathUnicode(fileLocalization, filepath);
		return chdir(Utils::convertWStringToString(fullfilepath).c_str()) == 0;
#else
#error
#endif
	}
Пример #29
0
static bool determineEntryCountAndWriteHeader(NexasPackage* package, const wchar_t* sourceDir, bool isBfeFormat) {
	writeLog(LOG_VERBOSE, L"Generating package header......");
	package->header = malloc(sizeof(Header));
	memcpy(package->header->typeTag, "PAC", 3);
	package->header->magicByte = 0;
	package->header->variantTag = isBfeFormat ? CONTENT_LZSS : CONTENT_MAYBE_DEFLATE;
	package->header->entryCount = 0;

	writeLog(LOG_VERBOSE, L"Moving into source directory......");
	if (_wchdir(sourceDir) != 0) {
		writeLog(LOG_QUIET, L"ERROR: Unable to read the source directory!");
		return false;
	}

	struct _wfinddata_t foundFile;
	intptr_t handle = _wfindfirst(L"*", &foundFile);
	int status = 0;
	while (status == 0) {
		if ((foundFile.attrib & _A_SUBDIR) == 0)
			++(package->header->entryCount);
		status = _wfindnext(handle, &foundFile);
	}
	_findclose(handle);

	writeLog(LOG_NORMAL, L"Found %u entries in the source directory.",
			package->header->entryCount);

	if (package->header->entryCount == 0) {
		writeLog(LOG_QUIET, L"ERROR: There is nothing to pack!");
		return false;
	}

	/// Write the header.
	if (fwrite(package->header, sizeof(Header), 1, package->file) != 1) {
		writeLog(LOG_QUIET, L"ERROR: Unable to write to the target package!");
		return false;
	}

	writeLog(LOG_VERBOSE, L"Package Header Written.");

	return true;
}
Пример #30
0
/*----------------------------------------------------------------------*
                             rtp_wfile_setcwd
 *----------------------------------------------------------------------*/
int rtp_wfile_setcwd (unsigned short * name)
{
#if (_WIN32_WINNT) >= 0x0400
#ifdef RTP_DEBUG
    SetLastError (0);
#endif

    name = _rtp_unicode_name_to_winname (name);

    if (_wchdir ((const unsigned short *)name) != 0)
    {
#ifdef RTP_DEBUG
		RTP_DEBUG_OUTPUT_ERRNO("rtp_wfile_setcwd:");
#endif
        return (-1);
    }
    return (0);
#endif
	return (-1);
}