Browse Source

* always use the *W version of the Windows API in ExtractShortPathName() so
it works correctly regardless of white kind of string is passed in
(and return a string encoded in DefaultRTLFileSystemCodePage)

git-svn-id: trunk@26450 -

Jonas Maebe 11 years ago
parent
commit
5d389e99fd
1 changed files with 14 additions and 7 deletions
  1. 14 7
      rtl/objpas/sysutils/fina.inc

+ 14 - 7
rtl/objpas/sysutils/fina.inc

@@ -117,17 +117,24 @@ begin
 end;
 
 function ExtractShortPathName(Const FileName : PathStr) : PathStr;
-
+{$if defined(MSWINDOWS) and not defined(SYSUTILSUNICODE)}
+var
+  TempFile, TempResult: UnicodeString;
+{$endif}
 begin
 {$ifdef MSWINDOWS}
+{$if not defined(SYSUTILSUNICODE)}
+  TempFile:=FileName;
+  SetLength(TempResult,Max_Path);
+  SetLength(TempResult,GetShortPathNameW(PWideChar(TempFile), PWideChar(TempResult),Length(TempResult)));
+  widestringmanager.Unicode2AnsiMoveProc(PWideChar(TempResult),Result,DefaultRTLFileSystemCodePage,Length(TempResult));
+{$else not SYSUTILSUNICODE}
   SetLength(Result,Max_Path);
-  if sizeof(FileName[1])=1 then
-    SetLength(Result,GetShortPathNameA(PChar(FileName), PChar(Result),Length(Result)))
-  else
-    SetLength(Result,GetShortPathNameW(PWideChar(FileName), PWideChar(Result),Length(Result)));
-{$else}
+  SetLength(Result,GetShortPathNameW(PWideChar(FileName), PWideChar(Result),Length(Result)));
+{$endif not SYSUTILSUNICODE}
+{$else MSWindows}
   Result:=FileName;
-{$endif}
+{$endif MSWindows}
 end;
 
 {$DEFINE FPC_FEXPAND_SYSUTILS}