sysdir.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  4. member of the Free Pascal development team.
  5. FPC Pascal system unit for the Win32 API.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {*****************************************************************************
  13. Directory Handling
  14. *****************************************************************************}
  15. type
  16. TDirFnType=function(name:pointer):longbool;stdcall;
  17. function CreateDirectoryTrunc(name:pointer):longbool;stdcall;
  18. begin
  19. CreateDirectoryTrunc:=CreateDirectoryW(name,nil);
  20. end;
  21. procedure dirfn(afunc : TDirFnType;s:unicodestring);
  22. begin
  23. DoDirSeparators(s);
  24. if not aFunc(punicodechar(s)) then
  25. begin
  26. errno:=GetLastError;
  27. Errno2InoutRes;
  28. end;
  29. end;
  30. Procedure do_MkDir(const s: UnicodeString);
  31. begin
  32. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  33. end;
  34. Procedure do_RmDir(const s: UnicodeString);
  35. begin
  36. if (s ='.') then
  37. begin
  38. InOutRes := 16;
  39. exit;
  40. end;
  41. {$ifdef WINCE}
  42. if (s='..') then
  43. begin
  44. InOutRes := 5;
  45. exit;
  46. end;
  47. {$endif WINCE}
  48. dirfn(TDirFnType(@RemoveDirectoryW),s);
  49. {$ifdef WINCE}
  50. if (Inoutres=3) and (Pos(DirectorySeparator, s)<2) then
  51. Inoutres:=2;
  52. {$endif WINCE}
  53. end;
  54. Procedure do_ChDir(const s: UnicodeString);
  55. begin
  56. {$ifndef WINCE}
  57. dirfn(TDirFnType(@SetCurrentDirectoryW),s);
  58. if Inoutres=2 then
  59. Inoutres:=3;
  60. {$else WINCE}
  61. InOutRes:=3;
  62. {$endif WINCE}
  63. end;
  64. procedure do_GetDir (DriveNr: byte; var Dir: Unicodestring);
  65. {$ifndef WINCE}
  66. var
  67. Drive:array[0..3]of widechar;
  68. defaultdrive:boolean;
  69. savebuf: UnicodeString;
  70. len : integer;
  71. {$endif WINCE}
  72. begin
  73. {$ifndef WINCE}
  74. defaultdrive:=drivenr=0;
  75. if not defaultdrive then
  76. begin
  77. Drive[0]:=widechar(Drivenr+64);
  78. Drive[1]:=':';
  79. Drive[2]:=#0;
  80. Drive[3]:=#0;
  81. len:=GetCurrentDirectoryW(0,nil); // in TChar
  82. setlength(savebuf,len-1); // -1 because len is #0 inclusive
  83. GetCurrentDirectoryW(len,punicodechar(SaveBuf)); // in TChar
  84. if not SetCurrentDirectoryW(@Drive) then
  85. begin
  86. errno := word (GetLastError);
  87. Errno2InoutRes;
  88. Dir := widechar (DriveNr + 64) + ':\';
  89. SetCurrentDirectoryW(punicodechar(SaveBuf));
  90. Exit;
  91. end;
  92. end;
  93. len:=GetCurrentDirectoryW(0,nil);
  94. setlength(dir,len-1); // -1 because len is #0 inclusive
  95. GetCurrentDirectoryW(len,punicodechar(dir));
  96. if not defaultdrive then
  97. SetCurrentDirectoryW(punicodechar(SaveBuf));
  98. if not FileNameCasePreserving then
  99. dir:=upcase(dir);
  100. {$else WINCE}
  101. Dir:='\';
  102. {$endif WINCE}
  103. end;