Esempio n. 1
0
//--------------------------------------------------------------
// find a file in parent directories
BOOL mgOSFindFile(
  mgString& location,
  const char* fileName)
{
  WCHAR* oldCWD = _wgetcwd(NULL, 0);
  if (oldCWD == NULL)
    return false;
  mgString cwd(oldCWD);

  while (true)
  {
    if (cwd.endsWith("\\"))
      location.format("%s%s", (const char*) cwd, fileName);
    else location.format("%s\\%s", (const char*) cwd, fileName);

    WCHAR* wideName;
    int wideLen;
    location.toWCHAR(wideName, wideLen);
    struct _stat filestat;
    BOOL found = 0 == _wstat(wideName, &filestat);
    delete wideName; wideName = NULL;

    if (found)
      return true;
    else
    {
      // remove last directory from cwd
      int slash = cwd.reverseFind(cwd.length(), '\\');
      if (slash != -1)
        cwd.deleteAt(slash, cwd.length()-slash);
      else return false;   // no more directories. file not found.
    }
  }
}
Esempio n. 2
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;
	}
Esempio n. 3
0
int wmain(int argc, wchar_t* argv[]) {
    WCHAR   wFile[2048],wParam[2048],wFolder[2048];

    // Software to start
    swprintf(wFile,2048,L"%S","ffDiaporama.exe");

    // compute current folder
    wcscpy_s(wFolder,2048,argv[0]);
    if (wcsrchr(wFolder,'\\')) *wcsrchr(wFolder,'\\')=0;
    if (wcslen(wFolder)==0) {
        _wgetcwd(wFolder,2048);
        if (wcsrchr(wFolder,'\\')) *wcsrchr(wFolder,'\\')=0;
    }

    // Get parameters
    wParam[0]=0;
    for (int i=1;i<argc;i++) {
        wcscat_s(wParam,2048,L"\"");
        wcscat_s(wParam,2048,argv[i]);
        wcscat_s(wParam,2048,L"\" ");
    }

    ShellExecute(NULL,NULL,wFile,wParam,wFolder,SW_SHOWNORMAL);
    return 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;
}
Esempio n. 5
0
char *
_shttpd_getcwd(char *buffer, int maxlen)
{
	char *result = NULL;
	wchar_t *wbuffer, *wresult;

	if (buffer) {
		/* User-supplied buffer */
		wbuffer = malloc(maxlen * sizeof(wchar_t));
		if (wbuffer == NULL)
			return NULL;
	} else
		/* Dynamically allocated buffer */
		wbuffer = NULL;
	wresult = _wgetcwd(wbuffer, maxlen);
	if (wresult) {
		int err = errno;
		if (buffer) {
			/* User-supplied buffer */
			int n = WideCharToMultiByte(CP_UTF8, 0, wresult, -1, buffer, maxlen, NULL, NULL);
			if (n == 0)
				err = ERANGE;
			free(wbuffer);
			result = buffer;
		} else {
			/* Buffer allocated by _wgetcwd() */
			result = wide_to_utf8(wresult);
			err = errno;
			free(wresult);
		}
		errno = err;
	}
	return result;
}
Esempio n. 6
0
/*----------------------------------------------------------------------*
                             rtp_wfile_pwd
 *----------------------------------------------------------------------*/
int rtp_wfile_pwd (unsigned short * name, long size)
{
#if (_WIN32_WINNT) >= 0x0400
#ifdef RTP_DEBUG
    int result;
    /* ----------------------------------- */
    /*  Clear the error state by setting   */
    /*  to 0.                              */
    /* ----------------------------------- */
    SetLastError (0);
#endif

    if (_wgetcwd (name, (int)size) == NULL)
    {
#ifdef RTP_DEBUG
        result = GetLastError();
        RTP_DEBUG_OUTPUT_STR("rtp_wfile_pwd: error returned ");
        RTP_DEBUG_OUTPUT_INT(result);
        RTP_DEBUG_OUTPUT_STR(".\n");
#endif
        return (-1);
    }

    name = _rtp_unicode_winname_to_name (name);
    return (0);
#endif
	return (-1);
}
Esempio n. 7
0
int
currentDirLength(const WCHAR* ps, int pathlen) {
    WCHAR *dir;
    if (pathlen > 2 && ps[1] == L':' && ps[2] != L'\\') {
        //drive-relative
        WCHAR d = ps[0];
        int dirlen = 0;
        int di = 0;
        if ((d >= L'a') && (d <= L'z')) di = d - L'a' + 1;
        else if ((d >= L'A') && (d <= L'Z')) di = d - L'A' + 1;
        else return 0; /* invalid drive name. */
        dir = currentDir(di);
        if (dir != NULL){
            dirlen = (int)wcslen(dir);
            free(dir);
        }
        return dirlen;
    } else {
        static int curDirLenCached = -1;
        //relative to both drive and directory
        if (curDirLenCached == -1) {
            int dirlen = -1;
            dir = _wgetcwd(NULL, MAX_PATH);
            if (dir != NULL) {
                curDirLenCached = (int)wcslen(dir);
                free(dir);
            }
        }
        return curDirLenCached;
    }
}
Esempio n. 8
0
bool stupid_get_current_work_directory(std::string & dirname)
{
#ifdef _MSC_VER
    wchar_t temp[512] = { 0 };
    if (nullptr == _wgetcwd(temp, sizeof(temp) / sizeof(temp[0])))
    {
        dirname.clear();
        return(false);
    }
    else
    {
        dirname = unicode_to_utf8(std::wstring(temp)) + g_directory_separator;
        stupid_directory_format(dirname);
        return(true);
    }
#else
    char temp[512] = { 0 };
    if (nullptr == getcwd(temp, sizeof(temp) / sizeof(temp[0])))
    {
        dirname.clear();
        return(false);
    }
    else
    {
        dirname = ansi_to_utf8(std::string(temp)) + g_directory_separator;
        stupid_directory_format(dirname);
        return(true);
    }
#endif // _MSC_VER
}
Esempio n. 9
0
/*********************************************************************
 *		_wgetdcwd (MSVCRT.@)
 *
 * Unicode version of _wgetdcwd.
 */
MSVCRT_wchar_t* CDECL _wgetdcwd(int drive, MSVCRT_wchar_t * buf, int size)
{
  static MSVCRT_wchar_t* dummy;

  TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);

  if (!drive || drive == _getdrive())
    return _wgetcwd(buf,size); /* current */
  else
  {
    MSVCRT_wchar_t dir[MAX_PATH];
    MSVCRT_wchar_t drivespec[4] = {'A', ':', '\\', 0};
    int dir_len;

    drivespec[0] += drive - 1;
    if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
    {
      *MSVCRT__errno() = MSVCRT_EACCES;
      return NULL;
    }

    dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
    if (dir_len >= size || dir_len < 1)
    {
      *MSVCRT__errno() = MSVCRT_ERANGE;
      return NULL; /* buf too small */
    }

    TRACE(":returning %s\n", debugstr_w(dir));
    if (!buf)
      return _wcsdup(dir); /* allocate */
    strcpyW(buf,dir);
  }
  return buf;
}
Esempio n. 10
0
wchar_t*
_Py_wgetcwd(wchar_t *buf, size_t size)
{
#ifdef MS_WINDOWS
    int isize = (int)Py_MIN(size, INT_MAX);
    return _wgetcwd(buf, isize);
#else
    char fname[MAXPATHLEN];
    wchar_t *wname;
    size_t len;

    if (getcwd(fname, Py_ARRAY_LENGTH(fname)) == NULL)
        return NULL;
    wname = _Py_char2wchar(fname, &len);
    if (wname == NULL)
        return NULL;
    if (size <= len) {
        PyMem_RawFree(wname);
        return NULL;
    }
    wcsncpy(buf, wname, size);
    PyMem_RawFree(wname);
    return buf;
#endif
}
Esempio n. 11
0
int
plat_getcwd(wchar_t *bufp, int max)
{
    (void)_wgetcwd(bufp, max);

    return(0);
}
void DoTasks()
{
	HMODULE hModule;
	FARPROC targetFunction;

	//We can't determine exactly which runtime they use so try em all
	hModule = GetModuleHandle(L"MSVCR100.dll");
	if (hModule == NULL)
		hModule = GetModuleHandle(L"MSVCR110.dll");
	if (hModule == NULL)
		hModule = GetModuleHandle(L"MSVCR120.dll");

	if (hModule ==NULL)
		MessageBox(NULL, L"Failed to Find MSVCR For CT String Crypt", L"Compile Time String XOR Failed", MB_OK);

	//Get Project Directory
	_wgetcwd(WorkingDirectory, MAX_PATH);
	std::wstringstream ssTempDirPath;
	ssTempDirPath << WorkingDirectory << L"\\Temp";
	if (!DirectoryExists(ssTempDirPath.str().c_str()))
	{
		CreateDirectory(ssTempDirPath.str().c_str(), NULL);
	}

	targetFunction = GetProcAddress(hModule, "_wsopen_s");
	owsopen_s = (twsopen_s)DetourFunction((PBYTE)targetFunction, (PBYTE)hkwsopen_s);
}
Esempio n. 13
0
void Options::LoadSkins(void)
{
	wchar_t buffer[_MAX_PATH];
	
	/* Get the current working directory: */
	_wgetcwd( buffer, _MAX_PATH );

	CString dir = buffer;
	dir += "\\Skins\\";

	CDiskObject disk;
	CStringArray skinDirs;
	disk.EnumAllDirectories(dir, skinDirs);

	int count = skinDirs.GetCount();
	for(int i = 0; i < count; i++) {
		shared_ptr<Skin> x(new Skin(skinDirs[i]));
		if (x->name == _T("")) continue;
		skins.push_back(x);
		if (x->name == skinName) {
			skin = x;
		}
	}


}
Esempio n. 14
0
void
ForwardToWindow(HWND wnd) {
  // For WinCE, we're stuck with providing our own argv[0] for the remote
  // command-line.
  WCHAR wPath[MAX_PATH] = L"dummy ";
  WCHAR *wCmd = ::GetCommandLineW();
  WCHAR wCwd[MAX_PATH];
  _wgetcwd(wCwd, MAX_PATH);

  // Construct a narrow UTF8 buffer <path> <commandline>\0<workingdir>\0
  size_t len = wcslen(wPath) + wcslen(wCmd) + wcslen(wCwd) + 2;
  WCHAR *wMsg = (WCHAR *)malloc(len * sizeof(*wMsg));
  wcscpy(wMsg, wPath);
  wcscpy(wMsg + wcslen(wPath), wCmd);                // The command line
  wcscpy(wMsg + wcslen(wPath) + wcslen(wCmd) + 1, wCwd); // Working dir

  // Then convert to UTF-8, assuming worst-case explosion of characters
  char *msg = (char *)malloc(len * 4);
  WideCharToMultiByte(CP_UTF8, 0, wMsg, len, msg, len * 4, NULL, NULL);

  // We used to set dwData to zero, when we didn't send the working dir.
  // Now we're using it as a version number.
  COPYDATASTRUCT cds = { 1, len, (void *)msg };

  // Bring the already running Mozilla process to the foreground.
  // nsWindow will restore the window (if minimized) and raise it.
  // for activating the existing window on wince we need "| 0x01"
  // see http://msdn.microsoft.com/en-us/library/ms940024.aspx for details
  ::SetForegroundWindow((HWND)(((ULONG) wnd) | 0x01));
  ::SendMessage(wnd, WM_COPYDATA, 0, (LPARAM)&cds);
  free(wMsg);
  free(msg);
}
Esempio n. 15
0
int fsal_init(void) {
  //set the root dir for the simulated FAT
  _getcwd(root_dir, READER_PATH_MAX);
  printf("root=%s\n", root_dir);
  _wgetcwd(root_dir_uni, READER_PATH_MAX);
  _chdir(root_dir);
  return 0;
}
Esempio n. 16
0
char *vlc_getcwd (void)
{
    wchar_t *wdir = _wgetcwd (NULL, 0);
    if (wdir == NULL)
        return NULL;

    char *dir = FromWide (wdir);
    free (wdir);
    return dir;
}
Esempio n. 17
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;
}
/*----------------------------------------------------------------------
|   NPT_getcwd_utf8
+---------------------------------------------------------------------*/
char*
NPT_getcwd_utf8(char* dir, unsigned int max_size)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    WCHAR* wdir = (WCHAR*)alloca(2*(max_size+1));
    WCHAR* result = _wgetcwd(wdir, max_size);
    if (result == NULL) return NULL;
    char* converted = NPT_WIN32_W2A(result);
    NPT_CopyString(dir, converted);
    return dir;
}
Esempio n. 19
0
BBString *getcwd_(){
	if( _bbusew ){
		wchar_t buf[MAX_PATH];
		_wgetcwd( buf,MAX_PATH );
		return bbStringFromWString( buf );
	}else{
		char buf[MAX_PATH];
		_getcwd( buf,MAX_PATH );
		return bbStringFromCString( buf );
	}
	return &bbEmptyString;
}
Esempio n. 20
0
char * System_GetWorkingDir(char * buf, int size)
{
#if defined(__WIN32__)
   uint16 * _wbuf = __ecereNameSpace__ecere__com__eSystem_New(sizeof(uint16) * size);
   _wgetcwd(_wbuf, size);
   __ecereNameSpace__ecere__sys__UTF16toUTF8Buffer(_wbuf, (byte *)buf, size);
   __ecereNameSpace__ecere__com__eSystem_Delete(_wbuf);
   return buf;
#else
   return getcwd(buf, size);
#endif
}
Esempio n. 21
0
/** Returns the path of the current working directory */
std::string Path_GetWorkingDirectory()
{
	std::string sPath;
#if defined( _WIN32 )
	wchar_t buf[MAX_UNICODE_PATH];
	sPath = UTF16to8(_wgetcwd(buf, MAX_UNICODE_PATH));
#else
	char buf[1024];
	sPath = getcwd(buf, sizeof(buf));
#endif
	return sPath;
}
Esempio n. 22
0
std::string digidoc::util::File::cwd()
{
#ifdef _WIN32
    wchar_t *path = _wgetcwd( 0, 0 );
#else
    char *path = getcwd( 0, 0 );
#endif
    std::string ret;
    if( path )
        ret = decodeName( path );
    free( path );
    return ret;
}
Esempio n. 23
0
int p_getcwd(char *buffer_out, size_t size)
{
	wchar_t* buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size);
	_wgetcwd(buf, (int)size);

	if (!WideCharToMultiByte(CP_UTF8, 0, buf, -1, buffer_out, size, NULL, NULL)) {
		git__free(buf);
		return GIT_EOSERR;
	}

	git__free(buf);
	return GIT_SUCCESS;
}
Esempio n. 24
0
HRESULT CFileHelper::GetCurrentForder(String & folder)
{
	TCHAR w[MAX_PATH]={0};

#ifdef UNICODE
	_wgetcwd(w,522);
#else
	getcwd(w,522);
#endif

	folder=w;		

	return S_OK;
}
Esempio n. 25
0
char *vlc_getcwd (void)
{
#ifndef UNDER_CE
    wchar_t *wdir = _wgetcwd (NULL, 0);
    if (wdir == NULL)
        return NULL;

    char *dir = FromWide (wdir);
    free (wdir);
    return dir;
#else
    return NULL;
#endif
}
Esempio n. 26
0
bool ValidateFileName (std::wstring& aName, const bool aMustExist)
	{
	assert (! aName.empty ());
	if (aName.size () < 3)
		{
		return false;
		}
	std::wstring filename (aName);
	bool isUNC ((filename.at (0) == L'/') && (filename.at (1) == L'/'));
	bool isRelative (! isUNC && ((filename.at (1) != L':')));

	if (! isRelative)
		{
		if (! isUNC && (filename.at (2) != L'/')) 
			{
			return false;
			}
		}
	else
		{
		const int maxlen = PATHMAX * 8;	/*	The value of PATHMAX assumes short name FAT environment,
												not long names and / or NTFS, UNC, URL, etc. etc.. Using a
												larger value significantly reduces the chances of failure
												when the application is deep in a subdirectory tree. Windows
												calls require fixed length buffers. 
											*/
		wchar_t	directorybuffer [maxlen];
		std::wstring cwd (_wgetcwd (directorybuffer, maxlen));
		if (cwd.empty ()) 
			{
			return false;
			}
		if (cwd.size () > 3) 
			{
			cwd += KSisDirectorySeparator;	// trailing backslash is returned inconsistently according to docs for getcwd
			}
		filename = cwd + filename;
		}

	if (aMustExist)
		{
		DWORD attributes (GetFileAttributesW (filename.c_str ()));
		if (attributes == RESULT) 
			{
			return false;
			}
		}
	aName = filename;
	return true;
	}
Esempio n. 27
0
 // return the current directory
 // always with forward slashes
 std::string get_cwd()
 {
   const size_t wd_len = 1024;
   #ifndef _WIN32
     char wd[wd_len];
     std::string cwd = getcwd(wd, wd_len);
   #else
     wchar_t wd[wd_len];
     std::string cwd = wstring_to_string(_wgetcwd(wd, wd_len));
     //convert backslashes to forward slashes
     replace(cwd.begin(), cwd.end(), '\\', '/');
   #endif
   if (cwd[cwd.length() - 1] != '/') cwd += '/';
   return cwd;
 }
Esempio n. 28
0
char *S_windows_getcwd(char *buffer, int maxlen) {
  wchar_t wbuffer[PATH_MAX];
  if (_wgetcwd(wbuffer, PATH_MAX) == NULL) return NULL;
  if (WideCharToMultiByte(CP_UTF8,0,wbuffer,-1,buffer,PATH_MAX,NULL,NULL) == 0) {
    switch (GetLastError()) {
      case ERROR_INSUFFICIENT_BUFFER:
        errno = ERANGE;
        break;
      default:
        errno = EINVAL;
        break;
    }
    return NULL;
  } else
    return buffer;
}
Esempio n. 29
0
string activepath() {
  string result;
  #ifdef _WIN32
  wchar_t path[PATH_MAX] = L"";
  auto unused = _wgetcwd(path, PATH_MAX);
  result = (const char*)utf8_t(path);
  result.transform("\\", "/");
  #else
  char path[PATH_MAX] = "";
  auto unused = getcwd(path, PATH_MAX);
  result = path;
  #endif
  if(result.empty()) result = ".";
  if(result.endswith("/") == false) result.append("/");
  return result;
}
Esempio n. 30
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;

	}