Exemple #1
0
plFileName plFileName::AbsolutePath() const
{
    if (!IsValid())
        return *this;

    plFileName path = Normalize();

#if HS_BUILD_FOR_WIN32
    plStringBuffer<wchar_t> wideName = path.fName.ToWchar();
    wchar_t path_sm[MAX_PATH];
    uint32_t path_length = GetFullPathNameW(wideName, MAX_PATH, path_sm, nullptr);
    if (path_length >= MAX_PATH) {
        // Buffer not big enough
        wchar_t *path_lg = new wchar_t[path_length];
        GetFullPathNameW(wideName, path_length, path_lg, nullptr);
        path = plString::FromWchar(path_lg);
        delete [] path_lg;
    } else {
        path = plString::FromWchar(path_sm);
    }
#else
    char *path_a = realpath(path.fName.c_str(), nullptr);
    hsAssert(path_a, "Failure to get absolute path (unsupported libc?)");
    path = path_a;
    free(path_a);
#endif

    return path;
}
Exemple #2
0
static struct filename_representations
*filename_representations_new(const char *raw, int type)
{
    struct filename_representations *fr;
    char *display_pre;
    char *real_path;
#ifdef G_OS_WIN32
    DWORD buffer_length;
    gunichar2 *raw_utf16, *real_path_utf16;
#endif

    fr = g_malloc(sizeof(struct filename_representations));
    fr->type = type;
    fr->raw = g_strdup(raw);

#ifdef G_OS_WIN32
    raw_utf16 = g_utf8_to_utf16(fr->raw, -1, NULL, NULL, NULL);
    buffer_length = GetFullPathNameW(raw_utf16, 0, NULL, NULL);
    real_path_utf16 = g_malloc(buffer_length * sizeof(gunichar2));
    GetFullPathNameW(raw_utf16, buffer_length, real_path_utf16, NULL);
    real_path = g_utf16_to_utf8(raw_utf16, -1, NULL, NULL, NULL);
    g_free(real_path_utf16);
    g_free(raw_utf16);
#else
    real_path = realpath(fr->raw, NULL);
#endif
    display_pre = g_filename_display_name(real_path);
    fr->collate_key = g_utf8_collate_key_for_filename(display_pre, -1);

    fr->display = g_strescape(display_pre,
                              (const gchar *) strescape_exceptions);
    g_free(display_pre);
    g_free(real_path);
    return fr;
}
bool PutFilePathName1017(UnicodeFileName* aFullName, const wchar_t* pFileName)
{
	wchar_t* pFullName = aFullName->GetBuffer(MAX_PIC_PATH_LEN);
	
	wchar_t sFullName[MAX_PATH*2], *pszPart=NULL;
	DWORD nCount = sizeof(sFullName)/sizeof(sFullName[0]);
	
	bool result = false;
	DWORD nLen = GetFullPathNameW(pFileName, nCount, sFullName, &pszPart);
	if (!nLen)
		return false; // не смогли?
	if (nLen > nCount) {
		wchar_t* pszBuffer = (wchar_t*)malloc(nLen * sizeof(wchar_t));
		_ASSERTE(pszBuffer);
		nLen = GetFullPathNameW(pFileName, nLen, pszBuffer, &pszPart);
		if (nLen) {
			aFullName->Assign(pszBuffer);
			result = true;
		}
		free(pszBuffer);
	} else {
		aFullName->Assign(sFullName);
		result = true;
	}
	
	return result;
}
Exemple #4
0
wstring get_full_path_name(const wstring& path) {
  Buffer<wchar_t> buf(MAX_PATH);
  DWORD size = GetFullPathNameW(path.c_str(), static_cast<DWORD>(buf.size()), buf.data(), nullptr);
  if (size > buf.size()) {
    buf.resize(size);
    size = GetFullPathNameW(path.c_str(), static_cast<DWORD>(buf.size()), buf.data(), nullptr);
  }
  CHECK_SYS(size);
  return wstring(buf.data(), size);
}
Exemple #5
0
static
rc_t make_absolute_and_transform_to_utf8_and_make_vpath ( const VFSManager * self,
    VPath ** new_path, const wchar_t * src, bool have_drive )
{
    rc_t rc;
    wchar_t full [ 4096 ];

    /* expand to full path - this is temporary, and will be replaced after KFS is updated */
    DWORD len = GetFullPathNameW ( src, sizeof full / sizeof full [ 0 ], full, NULL );
    if ( len == 0 )
    {
        /* we have an error */
        DWORD status = GetLastError ();
        DBGMSG ( DBG_VFS, DBG_FLAG_ANY, ( "GetFullPathNameW: error code - %u.\n", status ) );
        rc = RC ( rcVFS, rcMgr, rcConstructing, rcPath, rcInvalid );
    }
    else if ( len >= sizeof full / sizeof full [ 0 ] )
    {
        /* the buffer is too small ! */
        wchar_t * big_buf = malloc( ( ++len ) * ( sizeof full[ 0 ] ) );
        if ( big_buf == NULL )
            rc = RC ( rcVFS, rcMgr, rcConstructing, rcMemory, rcExhausted );
        else
        {
            DWORD len2 = GetFullPathNameW ( src, len, big_buf, NULL );
            if ( len2 == 0 )
            {
                /* we have an error */
                DWORD status = GetLastError ();
                DBGMSG ( DBG_VFS, DBG_FLAG_ANY, ( "GetFullPathNameW: error code - %u.\n", status ) );
                rc = RC ( rcVFS, rcMgr, rcConstructing, rcPath, rcInvalid );
            }
            else if ( len2 >= len )
            {
                DBGMSG ( DBG_VFS, DBG_FLAG_ANY, ( "GetFullPathNameW: buffer too small again - %u.\n", len2 ) );
                rc = RC ( rcVFS, rcMgr, rcConstructing, rcPath, rcInvalid );
            }
            else
            {
                /* now we can call the final transform and make */
                rc = transform_to_utf8_and_make_vpath( self, new_path, big_buf, true );
            }
            free( big_buf );
        }
    }
    else
    {
        /* now we can call the final transform and make */
        rc = transform_to_utf8_and_make_vpath( self, new_path, full, true );
    }
    return rc;
}
Exemple #6
0
/**
 * Get the real (no symlinks, no . or .. components) path, must exist.
 *
 * @returns iprt status code.
 * @param   pszPath         The path to resolve.
 * @param   pszRealPath     Where to store the real path.
 * @param   cchRealPath     Size of the buffer.
 */
RTDECL(int) RTPathReal(const char *pszPath, char *pszRealPath, size_t cchRealPath)
{
    /*
     * Convert to UTF-16, call Win32 APIs, convert back.
     */
    PRTUTF16 pwszPath;
    int rc = RTStrToUtf16(pszPath, &pwszPath);
    if (!RT_SUCCESS(rc))
        return (rc);

    LPWSTR lpFile;
    WCHAR  wsz[RTPATH_MAX];
    rc = GetFullPathNameW((LPCWSTR)pwszPath, RT_ELEMENTS(wsz), &wsz[0], &lpFile);
    if (rc > 0 && rc < RT_ELEMENTS(wsz))
    {
        /* Check that it exists. (Use RTPathAbs() to just resolve the name.) */
        DWORD dwAttr = GetFileAttributesW(wsz);
        if (dwAttr != INVALID_FILE_ATTRIBUTES)
            rc = RTUtf16ToUtf8Ex((PRTUTF16)&wsz[0], RTSTR_MAX, &pszRealPath, cchRealPath, NULL);
        else
            rc = RTErrConvertFromWin32(GetLastError());
    }
    else if (rc <= 0)
        rc = RTErrConvertFromWin32(GetLastError());
    else
        rc = VERR_FILENAME_TOO_LONG;

    RTUtf16Free(pwszPath);

    return rc;
}
	static std::string absolute_path(const std::string &path) {
		std::wstring wpath = transcode_utf8_to_utf16(path);
		wchar_t buf[MAX_PATH+1];
		DWORD len = GetFullPathNameW(wpath.c_str(), MAX_PATH, buf, 0);
		buf[len] = L'\0';
		return transcode_utf16_to_utf8(buf, len);
	}
Exemple #8
0
bool ConvertToNtPath(const wchar_t* path, wchar_t* normalized, size_t normalizedLen)
{
	UNICODE_STRING ntPath;
	DWORD size;
	bool result = false;

	size = GetFullPathNameW(path, (DWORD)normalizedLen, normalized, NULL);
	if (size == 0)
		return false;

	memset(&ntPath, 0, sizeof(ntPath));

	if (RtlDosPathNameToRelativeNtPathName_U(normalized, &ntPath, NULL, NULL) == FALSE)
		return false;

	if (normalizedLen * sizeof(wchar_t) > ntPath.Length)
	{
		memcpy(normalized, ntPath.Buffer, ntPath.Length);
		normalized[ntPath.Length / sizeof(wchar_t)] = L'\0';
		result = true;
	}

	HeapFree(GetProcessHeap(), 0, ntPath.Buffer);

	return result;
}
void cmdLogFile(int argc, wchar_t** argv)
{
	TurnOffLogFile();

	const wchar_t* fileName = L"HeapMonitorTrace.log";
	if (argc >= 1)
	{
		// turn off
		if (_wcsicmp(argv[0], L"off") == 0)
		{
			wprintf(L"LogFile is turned off\n");
			return;
		}
		else
		{
			fileName = argv[0];
		}
	}

	g_logFile = CreateFileW(fileName, GENERIC_WRITE, FILE_SHARE_READ, NULL,
		OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (g_logFile == INVALID_HANDLE_VALUE) {
		wprintf(L"Cannot open LogFile %ls\n", fileName);
		return;
	}

	SetFilePointer(g_logFile, 0, NULL, FILE_END);

	wchar_t fullName[MAX_PATH] = { 0 };
	wchar_t *pszFilePart = NULL;
	GetFullPathNameW(fileName, MAX_PATH, fullName, &pszFilePart);
	wprintf(L"LogFile is turned on, File=%ls\n", fullName);
}
bool FolderBrowserDialog::SetBufFromDir(const wchar_t * src, wchar_t* buf, int blen)
{
	DWORD retlen = GetFullPathNameW(src, blen, buf, NULL);
	if (retlen && retlen < MAX_WPATH && PathIsDirectoryW(buf))
		return true;
	return false;
}
Exemple #11
0
static dev_t stat_dev_for(const wchar_t *wpathname)
{
	DWORD len;
	wchar_t *fullpath;

	len = GetFullPathNameW(wpathname, 0, NULL, NULL);
	fullpath = __builtin_alloca((len + 1) * sizeof(wchar_t));
	if(!GetFullPathNameW(wpathname, len, fullpath, NULL)) {
		fprintf(stderr, "tup error: GetFullPathNameW(\"%ls\") failed: 0x%08lx\n", wpathname, GetLastError());
		return 0;
	}
	if(fullpath[1] != L':') {
		return 0;
	}
	return fullpath[0] - L'A';
}
Exemple #12
0
result_t path_base::fullpath(exlib::string path, exlib::string &retVal)
{
#ifdef _WIN32
    exlib::wstring str = utf8to16String(path);
    exlib::wchar utf16_buffer[MAX_PATH];

    DWORD utf16_len = GetFullPathNameW(str.c_str(), MAX_PATH, utf16_buffer, NULL);
    if (!utf16_len)
        return CHECK_ERROR(LastError());

    retVal = utf16to8String(utf16_buffer, (int32_t)utf16_len);
    return 0;
#else
    if (isPathSlash(path.c_str()[0]))
        return normalize(path, retVal);

    exlib::string str;

    process_base::cwd(str);
    str.append(1, PATH_SLASH);
    str.append(path);

    return normalize(str, retVal);
#endif
}
Exemple #13
0
/*****************************************************************************
 * SIC_GetIconIndex            [internal]
 *
 * Parameters
 *    sSourceFile    [IN]    filename of file containing the icon
 *    index        [IN]    index/resID (negated) in this file
 *
 * NOTES
 *  look in the cache for a proper icon. if not available the icon is taken
 *  from the file and cached
 */
INT SIC_GetIconIndex (LPCWSTR sSourceFile, INT dwSourceIndex, DWORD dwFlags )
{
    SIC_ENTRY sice;
    INT ret, index = INVALID_INDEX;
    WCHAR path[MAX_PATH];

    TRACE("%s %i\n", debugstr_w(sSourceFile), dwSourceIndex);

    GetFullPathNameW(sSourceFile, MAX_PATH, path, NULL);
    sice.sSourceFile = path;
    sice.dwSourceIndex = dwSourceIndex;
    sice.dwFlags = dwFlags;

    EnterCriticalSection(&SHELL32_SicCS);

    if (NULL != DPA_GetPtr (sic_hdpa, 0))
    {
      /* search linear from position 0*/
      index = DPA_Search (sic_hdpa, &sice, 0, SIC_CompareEntries, 0, DPAS_SORTED);
    }

    if ( INVALID_INDEX == index )
    {
          ret = SIC_LoadIcon (sSourceFile, dwSourceIndex, dwFlags);
    }
    else
    {
      TRACE("-- found\n");
      ret = ((LPSIC_ENTRY)DPA_GetPtr(sic_hdpa, index))->dwListIndex;
    }

    LeaveCriticalSection(&SHELL32_SicCS);
    return ret;
}
Exemple #14
0
extern "C" DWORD WINAPI dllGetFullPathNameW(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR* lpFilePart)
{
#ifdef TARGET_WINDOWS
  if (!lpFileName) return 0;
  if(wcsstr(lpFileName, L"://"))
  {
    size_t length = wcslen(lpFileName);
    if (nBufferLength < (length + 1))
      return length + 1;
    else
    {
      wcscpy(lpBuffer, lpFileName);
      if(lpFilePart)
      {
        wchar_t* s1 = wcsrchr(lpBuffer, '\\');
        wchar_t* s2 = wcsrchr(lpBuffer, '/');
        if(s2 && s1 > s2)
          *lpFilePart = s1 + 1;
        else if(s1 && s2 > s1)
          *lpFilePart = s2 + 1;
        else
          *lpFilePart = lpBuffer;
      }
      return length;
    }
  }
  return GetFullPathNameW(lpFileName, nBufferLength, lpBuffer, lpFilePart);
#else
  not_implement("kernel32.dll fake function GetFullPathNameW called\n"); //warning
  return 0;
#endif
}
Exemple #15
0
char *p_realpath(const char *orig_path, char *buffer)
{
	int ret;
	wchar_t* orig_path_w = gitwin_to_utf16(orig_path);
	wchar_t* buffer_w = (wchar_t*)git__malloc(GIT_PATH_MAX * sizeof(wchar_t));

	ret = GetFullPathNameW(orig_path_w, GIT_PATH_MAX, buffer_w, NULL);
	git__free(orig_path_w);

	if (!ret || ret > GIT_PATH_MAX) {
		buffer = NULL;
		goto done;
	}

	if (buffer == NULL) {
		int buffer_sz = WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, NULL, 0, NULL, NULL);

		if (!buffer_sz ||
			!(buffer = (char *)git__malloc(buffer_sz)) ||
			!WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, buffer, buffer_sz, NULL, NULL))
		{
			git__free(buffer);
			buffer = NULL;
		}
	} else {
		if (!WideCharToMultiByte(CP_UTF8, 0, buffer_w, -1, buffer, GIT_PATH_MAX, NULL, NULL))
			buffer = NULL;
	}

done:
	git__free(buffer_w);
	if (buffer)
		git_path_mkposix(buffer);
	return buffer;
}
Exemple #16
0
void ConvertNameToFull(const wchar *Src,wchar *Dest)
{
  if (Src==NULL || *Src==0)
  {
    *Dest=0;
    return;
  }
#ifdef _WIN_32
  if (WinNT())
  {
    wchar FullName[NM],*NamePtr;
    if (GetFullPathNameW(Src,sizeof(FullName)/sizeof(FullName[0]),FullName,&NamePtr))
      strcpyw(Dest,FullName);
    else
      if (Src!=Dest)
        strcpyw(Dest,Src);
  }
  else
  {
    char AnsiName[NM];
    WideToChar(Src,AnsiName);
    ConvertNameToFull(AnsiName,AnsiName);
    CharToWide(AnsiName,Dest);
  }
#else
  char AnsiName[NM];
  WideToChar(Src,AnsiName);
  ConvertNameToFull(AnsiName,AnsiName);
  CharToWide(AnsiName,Dest);
#endif
}
Exemple #17
0
INT
SheChangeDirW(
   register WCHAR *newdir
   )
{
   WCHAR       denvname[ 4 ];
   WCHAR       newpath[ MAX_PATH ];
   WCHAR       denvvalue[ MAX_PATH ];
   WCHAR       c, *s;
   DWORD       attr;

   GetCurrentDirectoryW( MAX_PATH, denvvalue );
   c = (WCHAR)(DWORD)CharUpperW((LPTSTR)(DWORD)denvvalue[0]);

   denvname[0] = WCHAR_EQUAL;
   if (IsCharAlphaW(*newdir) && newdir[1] == WCHAR_COLON) {
      denvname[1] = (WCHAR)(DWORD)CharUpperW((LPTSTR)(DWORD)*newdir);
      newdir += 2;
   } else {
      denvname[ 1 ] = c;
   }
   denvname[ 2 ] = WCHAR_COLON;
   denvname[ 3 ] = WCHAR_NULL;

   if ((*newdir == WCHAR_BSLASH) || (*newdir == WCHAR_SLASH)) {
      newpath[ 0 ] = denvname[ 1 ];
      newpath[ 1 ] = denvname[ 2 ];
      wcscpy( &newpath[ 2 ], newdir );
   } else {
      if (NULL != (s = SheGetEnvVarW( denvname ))) {
         wcscpy( newpath, s );
      } else {
         newpath[ 0 ] = denvname[ 1 ];
         newpath[ 1 ] = denvname[ 2 ];
         newpath[ 2 ] = WCHAR_NULL;
      }
      s = newpath + wcslen( newpath );
      *s++ = WCHAR_BSLASH;
      wcscpy( s, newdir );
   }

   if (!GetFullPathNameW(newpath, MAX_PATH, denvvalue, &s )) {
      return( ERROR_ACCESS_DENIED );
   }

   attr = GetFileAttributesW( denvvalue );
   if (attr == -1 || !(attr & FILE_ATTRIBUTE_DIRECTORY)) {
      return( ERROR_ACCESS_DENIED );
   }

   if (SheSetEnvVarW(denvname,denvvalue)) {
      return( ERROR_NOT_ENOUGH_MEMORY );
   }

   SetCurrentDirectoryW( denvvalue );

   // this seems wrong... SheGetDir(GD_DEFAULT, CurDrvDirW) ;
   wcscpy(CurDrvDirW, denvvalue);   // this seems right to me.
   return(SUCCESS) ;
}
Exemple #18
0
/*********************************************************************
 *		_wgetdcwd (MSVCRT.@)
 *
 * Unicode version of _wgetdcwd.
 */
MSVCRT_wchar_t* CDECL MSVCRT__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 == MSVCRT__getdrive())
    return MSVCRT__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 MSVCRT__wcsdup(dir); /* allocate */
    strcpyW(buf,dir);
  }
  return buf;
}
Exemple #19
0
local int FSusesLocalTimeW(const wchar_t *path)
{
    wchar_t  *tmp0;
    wchar_t   rootPathName[4];
    wchar_t   tmp1[MAX_PATH], tmp2[MAX_PATH];
    DWORD  volSerNo, maxCompLen, fileSysFlags;
#if defined(__RSXNT__)  /* RSXNT/EMX C rtl uses OEM charset */
    wchar_t *ansi_path = (wchar_t *)alloca((wcslen(path) + 1) * sizeof(wchar_t));

    CharToAnsiW(path, ansi_path);
    path = ansi_path;
#endif

    if (iswalpha(path[0]) && (path[1] == (wchar_t)':'))
        tmp0 = (wchar_t *)path;
    else
    {
        GetFullPathNameW(path, MAX_PATH, tmp1, &tmp0);
        tmp0 = &tmp1[0];
    }
    wcsncpy(rootPathName, tmp0, 3);   /* Build the root path name, */
    rootPathName[3] = (wchar_t)'\0';           /* e.g. "A:/"                */

    GetVolumeInformationW(rootPathName, tmp1, (DWORD)MAX_PATH,
                         &volSerNo, &maxCompLen, &fileSysFlags,
                         tmp2, (DWORD)MAX_PATH);

    /* Volumes in (V)FAT and (OS/2) HPFS format store file timestamps in
     * local time!
     */
    return !wcsncmp(_wcsupr(tmp2), L"FAT", 3) ||
           !wcsncmp(tmp2, L"VFAT", 4) ||
           !wcsncmp(tmp2, L"HPFS", 4);

} /* end function FSusesLocalTimeW() */
Exemple #20
0
static std::string getFullyQualifiedPathName(const std::string& filename)
{
	const DWORD bufferSize = 0x200;
	wchar_t buffer[bufferSize];
	GetFullPathNameW(toWideString(filename).c_str(), bufferSize, buffer, nullptr);
	return toUtf8(buffer);
}
Exemple #21
0
BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
{
    WCHAR buf[INTERNET_MAX_URL_LENGTH];
    WCHAR full_path[MAX_PATH];
    LPWSTR ptr;

    static const WCHAR url_format[] =
        {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
    static const WCHAR slash[] = {'/',0};
    static const WCHAR empty[] = {0};

    TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));

    if (!info->web_browser)
        return FALSE;

    if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) {
        WARN("GetFullPathName failed: %u\n", GetLastError());
        return FALSE;
    }

    wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index);

    /* FIXME: HACK */
    if((ptr = strchrW(buf, '#')))
       *ptr = 0;

    return SUCCEEDED(navigate_url(info, buf));
}
Exemple #22
0
/***********************************************************************
 *		SetupIterateCabinetW (SETUPAPI.@)
 */
BOOL WINAPI SetupIterateCabinetW(PCWSTR CabinetFile, DWORD Reserved,
                                 PSP_FILE_CALLBACK_W MsgHandler, PVOID Context)
{
  CHAR pszCabinet[MAX_PATH], pszCabPath[MAX_PATH];
  UINT len;
  SC_HSC_W my_hsc;
  ERF erf;
  WCHAR pszCabPathW[MAX_PATH], *p;
  DWORD fpnsize;
  BOOL ret;

  TRACE("(CabinetFile == %s, Reserved == %u, MsgHandler == ^%p, Context == ^%p)\n",
        debugstr_w(CabinetFile), Reserved, MsgHandler, Context);

  if (!LoadCABINETDll())
    return FALSE;

  if (!CabinetFile) return FALSE;

  memset(&my_hsc, 0, sizeof(SC_HSC_W));

  fpnsize = GetFullPathNameW(CabinetFile, MAX_PATH, pszCabPathW, &p);
  if (fpnsize > MAX_PATH) {
    SetLastError(ERROR_BAD_PATHNAME);
    return FALSE;
  }

  if (p) {
    strcpyW(my_hsc.most_recent_cabinet_name, p);
    *p = 0;
    len = WideCharToMultiByte(CP_ACP, 0, pszCabPathW, -1, pszCabPath,
				MAX_PATH, 0, 0);
    if (!len) return FALSE;
  } else {
    strcpyW(my_hsc.most_recent_cabinet_name, CabinetFile);
    pszCabPath[0] = '\0';
  }

  len = WideCharToMultiByte(CP_ACP, 0, my_hsc.most_recent_cabinet_name, -1,
				pszCabinet, MAX_PATH, 0, 0);
  if (!len) return FALSE;

  TRACE("path: %s, cabfile: %s\n",
	debugstr_a(pszCabPath), debugstr_a(pszCabinet));

  my_hsc.magic = SC_HSC_W_MAGIC;
  my_hsc.msghandler = MsgHandler;
  my_hsc.context = Context;
  my_hsc.hfdi = sc_FDICreate( sc_cb_alloc, sc_cb_free, sc_cb_open, sc_cb_read,
                              sc_cb_write, sc_cb_close, sc_cb_lseek, cpuUNKNOWN, &erf );

  if (!my_hsc.hfdi) return FALSE;

  ret = ( sc_FDICopy(my_hsc.hfdi, pszCabinet, pszCabPath,
                     0, sc_FNNOTIFY_W, NULL, &my_hsc)     ) ? TRUE : FALSE;

  sc_FDIDestroy(my_hsc.hfdi);
  return ret;
}
Exemple #23
0
/*****************************************************************************
 * SIC_IconAppend            [internal]
 *
 * NOTES
 *  appends an icon pair to the end of the cache
 */
static INT SIC_IconAppend (LPCWSTR sSourceFile, INT dwSourceIndex, HICON hSmallIcon, HICON hBigIcon, DWORD dwFlags)
{
    LPSIC_ENTRY lpsice;
    INT ret, index, index1, indexDPA;
    WCHAR path[MAX_PATH];
    TRACE("%s %i %p %p\n", debugstr_w(sSourceFile), dwSourceIndex, hSmallIcon ,hBigIcon);

    lpsice = (LPSIC_ENTRY) SHAlloc (sizeof (SIC_ENTRY));

    GetFullPathNameW(sSourceFile, MAX_PATH, path, NULL);
    lpsice->sSourceFile = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, (wcslen(path)+1)*sizeof(WCHAR) );
    wcscpy( lpsice->sSourceFile, path );

    lpsice->dwSourceIndex = dwSourceIndex;
    lpsice->dwFlags = dwFlags;

    EnterCriticalSection(&SHELL32_SicCS);

    indexDPA = DPA_Search (sic_hdpa, lpsice, 0, SIC_CompareEntries, 0, DPAS_SORTED|DPAS_INSERTAFTER);
    indexDPA = DPA_InsertPtr(sic_hdpa, indexDPA, lpsice);
    if ( -1 == indexDPA )
    {
        ret = INVALID_INDEX;
        goto leave;
    }

    index = ImageList_AddIcon (ShellSmallIconList, hSmallIcon);
    index1= ImageList_AddIcon (ShellBigIconList, hBigIcon);

    /* Something went wrong when allocating a new image in the list. Abort. */
    if((index == -1) || (index1 == -1))
    {
        WARN("Something went wrong when adding the icon to the list: small - 0x%x, big - 0x%x.\n",
            index, index1);
        if(index != -1) ImageList_Remove(ShellSmallIconList, index);
        if(index1 != -1) ImageList_Remove(ShellBigIconList, index1);
        ret = INVALID_INDEX;
        goto leave;
    }

    if (index!=index1)
    {
        FIXME("iconlists out of sync 0x%x 0x%x\n", index, index1);
        /* What to do ???? */
    }
    lpsice->dwListIndex = index;
    ret = lpsice->dwListIndex;

leave:
    if(ret == INVALID_INDEX)
    {
        if(indexDPA != -1) DPA_DeletePtr(sic_hdpa, indexDPA);
        HeapFree(GetProcessHeap(), 0, lpsice->sSourceFile);
        SHFree(lpsice);
    }
    LeaveCriticalSection(&SHELL32_SicCS);
    return ret;
}
	string GetFullPathname(const string &filename)
	{
		wstring wfn = StringFormat::UTF82Wide(filename);

		wchar_t path[512] = {0};
		GetFullPathNameW(wfn.c_str(), ARRAY_COUNT(path)-1, path, NULL);

		return StringFormat::Wide2UTF8(wstring(path));
	}
// Takes a relative/full path+fileName and returns the absolute path with drive
// letter, absolute path, fileName and extension of this file.
// Truncates total path/file length to CPUT_MAX_PATH. Both source and destination may be the same string.
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::ResolveAbsolutePathAndFilename(const std::wstring &fileName, std::wstring *pResolvedPathAndFilename)
{
    WCHAR pFullPathAndFilename[CPUT_MAX_PATH];
    DWORD result = GetFullPathNameW(fileName.c_str(), CPUT_MAX_PATH, pFullPathAndFilename, NULL);
    ASSERT( 0 != result, _L("Error getting full path name") );
    *pResolvedPathAndFilename = pFullPathAndFilename;

    return CPUT_SUCCESS;
}
Exemple #26
0
/*********************************************************************
 *      _wsearchenv (MSVCRT.@)
 *
 * Unicode version of _searchenv
 */
void CDECL MSVCRT__wsearchenv(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env, MSVCRT_wchar_t *buf)
{
  MSVCRT_wchar_t *envVal, *penv;
  MSVCRT_wchar_t curPath[MAX_PATH];

  *buf = '\0';

  /* Try CWD first */
  if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
  {
    GetFullPathNameW( file, MAX_PATH, buf, NULL );
    /* Sigh. This error is *always* set, regardless of success */
    msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
    return;
  }

  /* Search given environment variable */
  envVal = MSVCRT__wgetenv(env);
  if (!envVal)
  {
    msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
    return;
  }

  penv = envVal;
  TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal));

  do
  {
    MSVCRT_wchar_t *end = penv;

    while(*end && *end != ';') end++; /* Find end of next path */
    if (penv == end || !*penv)
    {
      msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
      return;
    }
    memcpy(curPath, penv, (end - penv) * sizeof(MSVCRT_wchar_t));
    if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
    {
      curPath[end - penv] = '\\';
      curPath[end - penv + 1] = '\0';
    }
    else
      curPath[end - penv] = '\0';

    strcatW(curPath, file);
    TRACE("Checking for file %s\n", debugstr_w(curPath));
    if (GetFileAttributesW( curPath ) != INVALID_FILE_ATTRIBUTES)
    {
      strcpyW(buf, curPath);
      msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
      return; /* Found */
    }
    penv = *end ? end + 1 : end;
  } while(1);
}
Exemple #27
0
/*
 * @implemented
 *
 * ripped from wine
 */
DWORD
WINAPI
GetTempPathW (
	DWORD	count,
   LPWSTR   path
	)
{
    static const WCHAR tmp[]  = { 'T', 'M', 'P', 0 };
    static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
    static const WCHAR userprofile[] = { 'U','S','E','R','P','R','O','F','I','L','E',0 };
    WCHAR tmp_path[MAX_PATH];
    UINT ret;

    TRACE("%u,%p\n", count, path);

    if (!(ret = GetEnvironmentVariableW( tmp, tmp_path, MAX_PATH )) &&
        !(ret = GetEnvironmentVariableW( temp, tmp_path, MAX_PATH )) &&
        !(ret = GetEnvironmentVariableW( userprofile, tmp_path, MAX_PATH )) &&
        !(ret = GetWindowsDirectoryW( tmp_path, MAX_PATH )))
        return 0;

   if (ret > MAX_PATH)
   {
     SetLastError(ERROR_FILENAME_EXCED_RANGE);
     return 0;
   }

   ret = GetFullPathNameW(tmp_path, MAX_PATH, tmp_path, NULL);
   if (!ret) return 0;

   if (ret > MAX_PATH - 2)
   {
     SetLastError(ERROR_FILENAME_EXCED_RANGE);
     return 0;
   }

   if (tmp_path[ret-1] != '\\')
   {
     tmp_path[ret++] = '\\';
     tmp_path[ret]   = '\0';
   }

   ret++; /* add space for terminating 0 */

   if (count)
   {
     lstrcpynW(path, tmp_path, count);
     if (count >= ret)
         ret--; /* return length without 0 */
     else if (count < 4)
         path[0] = 0; /* avoid returning ambiguous "X:" */
   }

   TRACE("GetTempPathW returning %u, %S\n", ret, path);
   return ret;

}
void DirMan::DirMan_private::setPath(const std::string &dirPath)
{
    m_dirPathW = Str2WStr(dirPath);
    wchar_t fullPath[MAX_PATH];
    GetFullPathNameW(m_dirPathW.c_str(), MAX_PATH, fullPath, NULL);
    m_dirPathW = fullPath;
    //Force UNIX paths
    std::replace(m_dirPathW.begin(), m_dirPathW.end(), L'\\', L'/');
    m_dirPath = WStr2Str(m_dirPathW);
    delEnd(m_dirPathW, L'/');
    delEnd(m_dirPath, '/');
}
Exemple #29
0
DWORD TP_GetFullPathName(LPWSTR fileName, DWORD nBufferLength, LPWSTR lpBuffer)
{
#ifdef WINDOWS
    return GetFullPathNameW(fileName, nBufferLength, lpBuffer, NULL);
#else
    char nativeFullPath[MAX_PATH];
    (void)realpath(HackyConvertToSTR(fileName), nativeFullPath);
    LPWSTR fullPathForCLR = HackyConvertToWSTR(nativeFullPath);
    wcscpy_s(lpBuffer, MAX_PATH, fullPathForCLR);
    return wcslen(lpBuffer);
#endif
}
Exemple #30
0
/**
@Status Caveat
@Notes This function can only find libraries in the root of the current
       package. The mode parameter is ignored. In addition, error information
       is not available on failure.
*/
void* dlopen(const char* path, int mode) {
    try {
        // We can only load libraries from within our own package or any dependent
        // packages, so absolute paths are not much use to us. From whatever path
        // we're given, just strip off everything but the leaf file name and try
        // to load that. This isn't always correct, but it is sometimes correct.

        std::wstring widePath(path, path + strlen(path));

        DWORD pathLength = GetFullPathNameW(widePath.c_str(), 0, nullptr, nullptr);
        auto fullPath = std::make_unique<WCHAR[]>(pathLength);
        LPWSTR fileName = nullptr;

        GetFullPathNameW(widePath.c_str(), pathLength, fullPath.get(), &fileName);

        return LoadPackagedLibrary(fileName, 0);
    } catch (...) {
    }

    return NULL;
}