| 1 | /* Initialize the temporary directory */
|
|---|
| 2 |
|
|---|
| 3 | /* Temporary directory Initialization
|
|---|
| 4 | Copyright (C) 2007-2017 Herwig Bauernfeind for bww bitwise works GmbH.
|
|---|
| 5 |
|
|---|
| 6 | This program is free software: you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | This program is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /*:VRX */
|
|---|
| 21 | _InitTempDir:
|
|---|
| 22 | IF options.!debug == 1 THEN say time()' _InitTempDir() started'
|
|---|
| 23 | /* Get temporary directory */
|
|---|
| 24 | HaveNoTMPDIR = 0
|
|---|
| 25 | TempDir = translate(value('TMPDIR',,'OS2ENVIRONMENT'),'\','/')
|
|---|
| 26 | IF options.!debug == 1 THEN say ' TMPDIR = "'TempDir'"'
|
|---|
| 27 | if TempDir = '' then do
|
|---|
| 28 | HaveNoTMPDIR = 1
|
|---|
| 29 | TempDir = translate(value('TEMP',,'OS2ENVIRONMENT'),'\','/')
|
|---|
| 30 | IF options.!debug == 1 THEN say ' TEMP = "'TempDir'"'
|
|---|
| 31 | end
|
|---|
| 32 | if TempDir = '' then do
|
|---|
| 33 | TempDir = translate(value('TMP',,'OS2ENVIRONMENT'),'\','/')
|
|---|
| 34 | IF options.!debug == 1 THEN say ' TMP = "'TempDir'"'
|
|---|
| 35 | end
|
|---|
| 36 | if TempDir = '' then do
|
|---|
| 37 | TempDir = directory()
|
|---|
| 38 | IF options.!debug == 1 THEN say ' Use current dir="'TempDir'"'
|
|---|
| 39 | end
|
|---|
| 40 | if HaveNoTMPDIR then do
|
|---|
| 41 | say 'WARNING! Setting missing TMPDIR variable to "'TempDir'".'
|
|---|
| 42 | IF options.!debug == 1 THEN say ' WARNING! Setting missing TMPDIR variable to "'TempDir'".'
|
|---|
| 43 | ok = value('TMPDIR',TempDir,'OS2ENVIRONMENT')
|
|---|
| 44 | end
|
|---|
| 45 | /* Remove trailing \, translate tabs into blanks */
|
|---|
| 46 | TempDir = translate(strip(TempDir,'T','\'),' ','09'x)
|
|---|
| 47 |
|
|---|
| 48 | /* Check if there are trailing blanks now - this is an error! */
|
|---|
| 49 | if strip(TempDir) <> TempDir then do
|
|---|
| 50 | say 'WARNING! Remove trailing blanks and tabs from temporary directory!'
|
|---|
| 51 | ok = value('TMPDIR',strip(TempDir),'OS2ENVIRONMENT')
|
|---|
| 52 | end
|
|---|
| 53 |
|
|---|
| 54 | /* In case it does not exist, create it */
|
|---|
| 55 | if \VRFileExists(TempDir) then do
|
|---|
| 56 | say 'WARNING! Temporary directory had to be created!'
|
|---|
| 57 | ok = SysMkDir(TempDir)
|
|---|
| 58 | end
|
|---|
| 59 |
|
|---|
| 60 | /* make sure there is a trailing "\" */
|
|---|
| 61 | Tempdir = strip(TempDir)||'\'
|
|---|
| 62 |
|
|---|
| 63 | IF options.!debug == 1 THEN say time()' _InitTempDir() done, we will use "'TempDir'"'
|
|---|
| 64 | return
|
|---|
| 65 |
|
|---|
| 66 | _ChkTempFreeSpace:
|
|---|
| 67 | IF options.!debug == 1 THEN say time()' _ChkTempFreeSpace() started'
|
|---|
| 68 | /* Check free space */
|
|---|
| 69 | TempDrvInfo = SysDriveInfo(left(TempDir,2))
|
|---|
| 70 | parse var TempDrvInfo . TempFreeSpace . .
|
|---|
| 71 | if TempFreeSpace < 1048576 then do
|
|---|
| 72 | say 'Warning: Free space on "'||TempDir||'" low!'
|
|---|
| 73 | end
|
|---|
| 74 | drop TempDrvInfo
|
|---|
| 75 | IF options.!debug == 1 THEN say time()' _ChkTempFreeSpace() done, got "'TempFreeSpace'"'
|
|---|
| 76 | return TempFreeSpace
|
|---|