| | 1 | | #pragma rtGlobals=3 |
| | 2 | | #pragma rtFunctionErrors=1 |
| | 3 | | #pragma version=1.10 |
| | 4 | | #pragma TextEncoding="UTF-8" |
| | 5 | | #pragma ModuleName=IUTF_Utils_Paths |
| | 6 | |
|
| | 7 | | ///@cond HIDDEN_SYMBOL |
| | 8 | |
|
| | 9 | | /// @brief Clears the current stored home path. The next call to GetHomePath() will return the |
| | 10 | | // current home path. |
| 5 | 11 | | static Function ClearHomePath() |
| 5 | 12 | | DFREF dfr = GetPackageFolder() |
| 5 | 13 | | KillStrings/Z dfr:homePath |
| 5 | 14 | | End |
| | 15 | |
|
| | 16 | | /// @brief Returns the home path at the start of the execution of RunTest. If this experiment wasn't |
| | 17 | | /// saved at this point it will return an empty string. |
| 10 | 18 | | static Function/S GetHomePath() |
| 10 | 19 | | DFREF dfr = GetPackageFolder() |
| 10 | 20 | | SVAR/Z/SDFR=dfr homePath |
| | 21 | |
|
| 10 | 22 | | if(SVAR_Exists(homePath)) |
| 5 | 23 | | return homePath |
| 5 | 24 | | endif |
| | 25 | |
|
| 5 | 26 | | PathInfo home |
| 5 | 27 | | if(V_flag) |
| 5 | 28 | | string/G dfr:homePath = S_path |
| 5 | 29 | | return S_path |
| 0 | 30 | | else |
| 0 | 31 | | string/G dfr:homePath = "" |
| 0 | 32 | | return "" |
| 0 | 33 | | endif |
| 10 | 34 | | End |
| | 35 | |
|
| | 36 | | /// @brief Get the full path of a file at the cached home directory |
| | 37 | | /// |
| | 38 | | /// @param fileName The file name that need to be located in the home directory |
| | 39 | | /// @param unusedName (optional, default 0=disabled) If set to 1 it will search for an unused file |
| | 40 | | /// name in the home directory with the same pattern as fileName. |
| | 41 | | /// If no unused file name could be found this function will abort the execution. |
| | 42 | | /// |
| | 43 | | /// @returns The full file path |
| 5 | 44 | | static Function/S AtHome(fileName, [unusedName]) |
| | 45 | | string fileName |
| | 46 | | variable unusedName |
| | 47 | |
|
| 5 | 48 | | string result, msg |
| | 49 | |
|
| 5 | 50 | | unusedName = ParamIsDefault(unusedName) ? 0 : !!unusedName |
| | 51 | |
|
| 5 | 52 | | result = GetHomePath() + fileName |
| | 53 | |
|
| 5 | 54 | | if(unusedName) |
| 5 | 55 | | result = getUnusedFileName(result) |
| 5 | 56 | | if(IUTF_Utils#IsEmpty(result)) |
| 0 | 57 | | sprintf msg, "Cannot determine unused file for %s at home directory", fileName |
| 0 | 58 | | IUTF_Reporting#ReportErrorAndAbort(msg) |
| 5 | 59 | | endif |
| 5 | 60 | | endif |
| | 61 | |
|
| 5 | 62 | | return result |
| 5 | 63 | | End |
| | 64 | |
|
| | 65 | | /// Returns 0 if the file exists, !0 otherwise |
| 5 | 66 | | static Function FileNotExists(fname) |
| | 67 | | string fname |
| | 68 | |
|
| 5 | 69 | | GetFileFolderInfo/Q/Z fname |
| 5 | 70 | | return V_Flag |
| 5 | 71 | | End |
| | 72 | |
|
| | 73 | | /// returns a non existing file name an empty string |
| 5 | 74 | | static Function/S getUnusedFileName(fname) |
| | 75 | | string fname |
| | 76 | |
|
| 5 | 77 | | variable count |
| 5 | 78 | | string fn, fnext, fnn |
| | 79 | |
|
| 5 | 80 | | if(FileNotExists(fname)) |
| 5 | 81 | | return fname |
| 0 | 82 | | endif |
| 0 | 83 | | fname = ParseFilePath(5, fname, "\\", 0, 0) |
| 0 | 84 | | fnext = "." + ParseFilePath(4, fname, "\\", 0, 0) |
| 0 | 85 | | fnn = RemoveEnding(fname, fnext) |
| | 86 | |
|
| 0 | 87 | | count = -1 |
| 0 | 88 | | do |
| 0 | 89 | | count += 1 |
| 0 | 90 | | sprintf fn, "%s_%03d%s", fnn, count, fnext |
| 0 | 91 | | while(!FileNotExists(fn) && count < 999) |
| 0 | 92 | | if(!FileNotExists(fn)) |
| 0 | 93 | | return "" |
| 0 | 94 | | endif |
| 0 | 95 | | return fn |
| 5 | 96 | | End |
| | 97 | |
|
| | 98 | | // Get the directory part of a file with a trailing back-slash |
| | 99 | | // |
| | 100 | | // Examples: |
| | 101 | | // C:\foo\bar\baz.txt -> C:\foo\bar\ |
| | 102 | | // C:\foo\bar\baz\ -> C:\foo\bar\ |
| 30 | 103 | | static Function/S GetDirPathOfFile(path) |
| | 104 | | string path |
| | 105 | |
|
| 30 | 106 | | path = ParseFilePath(5, path, "\\", 0, 0) |
| 30 | 107 | | path = ParseFilePath(1, path, "\\", 1, 0) |
| | 108 | |
|
| 30 | 109 | | return path |
| 30 | 110 | | End |
| | 111 | |
|
| | 112 | | ///@endcond // HIDDEN_SYMBOL |