osutil.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. <What does this file>
  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. Application name
  14. ---------------------------------------------------------------------}
  15. Function ApplicationName : String;
  16. begin
  17. If Assigned(OnGetApplicationName) then
  18. Result:=OnGetApplicationName()
  19. else
  20. Result:=ChangeFileExt(ExtractFileName(Paramstr(0)),'');
  21. end;
  22. { ---------------------------------------------------------------------
  23. Default implementations for AppConfigDir implementation.
  24. ---------------------------------------------------------------------}
  25. Function DGetAppConfigDir(Global : Boolean) : String;
  26. begin
  27. Result:=ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
  28. end;
  29. Function DGetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  30. begin
  31. Result:=ExtractFilePath(ParamStr(0));
  32. If SubDir then
  33. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  34. Result:=Result+ApplicationName+ConfigExtension;
  35. end;
  36. Function GetAppConfigFile(Global : Boolean) : String;
  37. begin
  38. Result:=GetAppConfigFile(Global,False);
  39. end;
  40. { ---------------------------------------------------------------------
  41. Fallback implementations for AppConfigDir implementation.
  42. ---------------------------------------------------------------------}
  43. {
  44. If a particular OS does it different:
  45. - set the HAVE_OSCONFIG define before including sysutils.inc.
  46. - implement the functions.
  47. Default config assumes a DOS-like configuration.
  48. }
  49. {$ifndef HAS_OSCONFIG}
  50. Function GetAppConfigDir(Global : Boolean) : String;
  51. begin
  52. Result:=DGetAppConfigDir(Global);
  53. end;
  54. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  55. begin
  56. Result:=DGetAppConfigFile(Global,Subdir);
  57. end;
  58. {$endif}
  59. { ---------------------------------------------------------------------
  60. Get temporary directory name
  61. ---------------------------------------------------------------------}
  62. {$ifndef HAS_TEMPDIR}
  63. Function GetTempDir(Global : Boolean) : String;
  64. begin
  65. If Assigned(OnGetTempDir) then
  66. Result:=OnGetTempDir(Global)
  67. else
  68. begin
  69. Result:=GetEnvironmentVariable('TEMP');
  70. If (Result='') Then
  71. Result:=GetEnvironmentVariable('TMP');
  72. end;
  73. if (Result<>'') then
  74. Result:=IncludeTrailingPathDelimiter(Result);
  75. end;
  76. {$endif}
  77. Function GetTempDir : String;
  78. begin
  79. Result:=GetTempDir(True);
  80. end;
  81. { ---------------------------------------------------------------------
  82. Get temporary file name
  83. ---------------------------------------------------------------------}
  84. {$ifndef HAS_TEMPFILE}
  85. Function GetTempFileName(Const Dir,Prefix : String) : String;
  86. Var
  87. I : Integer;
  88. Start : String;
  89. begin
  90. If Assigned(OnGetTempFile) then
  91. Result:=OnGetTempFile(Dir,Prefix)
  92. else
  93. begin
  94. If (Dir='') then
  95. Start:=GetTempDir
  96. else
  97. Start:=IncludeTrailingPathDelimiter(Dir);
  98. If (Prefix='') then
  99. Start:=Start+'TMP'
  100. else
  101. Start:=Start+Prefix;
  102. I:=0;
  103. Repeat
  104. Result:=Format('%s%.5d.tmp',[Start,I]);
  105. Inc(I);
  106. Until not FileExists(Result);
  107. end;
  108. end;
  109. {$endif}
  110. Function GetTempFileName : String;
  111. begin
  112. Result:=GetTempFileName('','');
  113. end;
  114. {
  115. $Log$
  116. Revision 1.2 2004-10-10 10:28:34 michael
  117. + Implementation of GetTempDir and GetTempFileName
  118. Revision 1.1 2004/08/05 07:28:01 michael
  119. + Added getappconfigdir calls
  120. }