| [2] | 1 | #define INCL_DOS | 
|---|
|  | 2 | #define INCL_DOSERRORS | 
|---|
|  | 3 | #define INCL_WIN | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #include <os2.h> | 
|---|
|  | 6 | #include <stdarg.h> | 
|---|
|  | 7 | #include <stdio.h> | 
|---|
|  | 8 | #include <stdlib.h> | 
|---|
|  | 9 | #include <string.h> | 
|---|
|  | 10 | #include <ctype.h> | 
|---|
|  | 11 | #include "fm3dll.h" | 
|---|
|  | 12 | #include "fm3dlg.h" | 
|---|
|  | 13 | #include "fm3str.h" | 
|---|
|  | 14 |  | 
|---|
|  | 15 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir) | 
|---|
|  | 16 |  | 
|---|
| [551] | 17 | APIRET MassMkdir(HWND hwndClient, CHAR * dir) | 
|---|
|  | 18 | { | 
|---|
| [2] | 19 |  | 
|---|
| [551] | 20 | APIRET last, was = 0; | 
|---|
|  | 21 | CHAR *p; | 
|---|
|  | 22 | CHAR s[CCHMAXPATH]; | 
|---|
| [2] | 23 |  | 
|---|
| [551] | 24 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s))) | 
|---|
|  | 25 | strcpy(s, dir); | 
|---|
| [2] | 26 | p = s; | 
|---|
| [551] | 27 | while (*p) { | 
|---|
|  | 28 | if (*p == '/') | 
|---|
| [2] | 29 | *p = '\\'; | 
|---|
|  | 30 | p++; | 
|---|
|  | 31 | } | 
|---|
|  | 32 | p = s; | 
|---|
|  | 33 | do { | 
|---|
| [551] | 34 | p = strchr(p, '\\'); | 
|---|
|  | 35 | if (p && p > s && *(p - 1) == ':') | 
|---|
|  | 36 | p = strchr(p + 1, '\\'); | 
|---|
|  | 37 | if (p && *p) { | 
|---|
| [2] | 38 | *p = 0; | 
|---|
|  | 39 | was = 1; | 
|---|
|  | 40 | } | 
|---|
|  | 41 | else | 
|---|
|  | 42 | was = 0; | 
|---|
| [551] | 43 | last = DosCreateDir(s, NULL); | 
|---|
|  | 44 | if (!last) | 
|---|
|  | 45 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID); | 
|---|
|  | 46 | else if (last == ERROR_ACCESS_DENIED) { | 
|---|
|  | 47 | if (!IsFile(s)) | 
|---|
|  | 48 | last = 0; | 
|---|
| [2] | 49 | } | 
|---|
| [551] | 50 | if (was) { | 
|---|
| [2] | 51 | *p = '\\'; | 
|---|
|  | 52 | p++; | 
|---|
|  | 53 | } | 
|---|
|  | 54 | } | 
|---|
| [551] | 55 | while (p && *p); | 
|---|
| [2] | 56 | return last; | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
| [551] | 59 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags) | 
|---|
|  | 60 | { | 
|---|
| [2] | 61 |  | 
|---|
|  | 62 | /* | 
|---|
|  | 63 | * bitmapped flags: | 
|---|
|  | 64 | * 1 = don't ask to create if non-existent | 
|---|
|  | 65 | */ | 
|---|
|  | 66 |  | 
|---|
| [551] | 67 | CHAR s[CCHMAXPATH], *p; | 
|---|
|  | 68 | APIRET ret = 0, error; | 
|---|
|  | 69 | INT isfile; | 
|---|
| [2] | 70 |  | 
|---|
| [551] | 71 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s))) | 
|---|
|  | 72 | strcpy(s, dir); | 
|---|
|  | 73 | while ((p = strchr(s, '/')) != NULL) | 
|---|
| [2] | 74 | *p = '\\'; | 
|---|
| [551] | 75 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\') | 
|---|
| [2] | 76 | s[strlen(s) - 1] = 0; | 
|---|
| [551] | 77 | if (IsFullName(s)) { | 
|---|
|  | 78 | if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) { | 
|---|
|  | 79 | if (!(flags & 1)) | 
|---|
|  | 80 | saymsg(MB_CANCEL, | 
|---|
|  | 81 | hwnd, | 
|---|
|  | 82 | GetPString(IDS_NOPETEXT), | 
|---|
|  | 83 | GetPString(IDS_DRIVEISTEXT), | 
|---|
|  | 84 | toupper(*s), | 
|---|
|  | 85 | ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ? | 
|---|
|  | 86 | GetPString(IDS_BEINGIGNOREDTEXT) : | 
|---|
|  | 87 | GetPString(IDS_INVALIDTEXT)); | 
|---|
| [2] | 88 | return -5; | 
|---|
|  | 89 | } | 
|---|
|  | 90 | } | 
|---|
|  | 91 | isfile = IsFile(s); | 
|---|
| [551] | 92 | if (isfile == -1) { | 
|---|
|  | 93 | if (IsFullName(s)) { | 
|---|
|  | 94 | if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) { | 
|---|
|  | 95 | if (!(flags & 1)) | 
|---|
|  | 96 | saymsg(MB_CANCEL, | 
|---|
|  | 97 | hwnd, | 
|---|
|  | 98 | GetPString(IDS_NOPETEXT), | 
|---|
|  | 99 | GetPString(IDS_DRIVEISTEXT), | 
|---|
|  | 100 | toupper(*s), GetPString(IDS_NOWRITETEXT)); | 
|---|
|  | 101 | return -4; | 
|---|
| [2] | 102 | } | 
|---|
|  | 103 | } | 
|---|
| [551] | 104 | if (!(flags & 1)) { | 
|---|
|  | 105 | if (saymsg(MB_YESNO, | 
|---|
|  | 106 | hwnd, | 
|---|
|  | 107 | GetPString(IDS_CONFIRMTEXT), | 
|---|
|  | 108 | GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES) | 
|---|
|  | 109 | return -3; | 
|---|
| [2] | 110 | } | 
|---|
| [551] | 111 | error = MassMkdir(hwndClient, s); | 
|---|
|  | 112 | if (error) { | 
|---|
| [2] | 113 | Dos_Error(MB_CANCEL, | 
|---|
| [551] | 114 | error, | 
|---|
|  | 115 | hwnd, | 
|---|
|  | 116 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s); | 
|---|
| [2] | 117 | ret = -1; | 
|---|
|  | 118 | } | 
|---|
|  | 119 | } | 
|---|
| [551] | 120 | else if (isfile) { | 
|---|
| [2] | 121 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
| [551] | 122 | hwnd, | 
|---|
|  | 123 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s); | 
|---|
| [2] | 124 | ret = -2; | 
|---|
|  | 125 | } | 
|---|
|  | 126 | return ret; | 
|---|
|  | 127 | } | 
|---|
|  | 128 |  | 
|---|
| [551] | 129 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy) | 
|---|
|  | 130 | { | 
|---|
| [2] | 131 |  | 
|---|
|  | 132 | STRINGINPARMS sip; | 
|---|
| [551] | 133 | CHAR szBuff[CCHMAXPATH]; | 
|---|
|  | 134 | APIRET error; | 
|---|
| [2] | 135 |  | 
|---|
|  | 136 | Over: | 
|---|
|  | 137 | sip.help = GetPString(IDS_MKDIRHELPTEXT); | 
|---|
|  | 138 | sip.ret = szBuff; | 
|---|
| [551] | 139 | if (filename) | 
|---|
|  | 140 | strcpy(szBuff, filename); | 
|---|
| [2] | 141 | else | 
|---|
|  | 142 | save_dir2(szBuff); | 
|---|
|  | 143 | MakeValidDir(szBuff); | 
|---|
| [551] | 144 | if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\') | 
|---|
|  | 145 | strcat(szBuff, "\\"); | 
|---|
| [2] | 146 | sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT); | 
|---|
|  | 147 | sip.inputlen = CCHMAXPATH - 1; | 
|---|
|  | 148 | sip.title = GetPString(IDS_MKDIRTITLETEXT); | 
|---|
| [551] | 149 | if (WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 150 | hwnd, | 
|---|
|  | 151 | InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) { | 
|---|
|  | 152 | if ((strchr(szBuff, '?') || | 
|---|
|  | 153 | strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) { | 
|---|
| [2] | 154 | saymsg(MB_ENTER | MB_ICONEXCLAMATION, | 
|---|
| [551] | 155 | hwnd, | 
|---|
|  | 156 | GetPString(IDS_ERRORTEXT), | 
|---|
|  | 157 | GetPString(IDS_DIRNAMEERRORTEXT), szBuff); | 
|---|
| [2] | 158 | goto Over; | 
|---|
|  | 159 | } | 
|---|
| [551] | 160 | error = MassMkdir(hwnd, szBuff); | 
|---|
|  | 161 | if (error) | 
|---|
| [2] | 162 | Dos_Error(MB_ENTER, | 
|---|
| [551] | 163 | error, | 
|---|
|  | 164 | hwnd, | 
|---|
|  | 165 | __FILE__, | 
|---|
|  | 166 | __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff); | 
|---|
| [2] | 167 | else { | 
|---|
| [551] | 168 | if (copy && filename) | 
|---|
|  | 169 | strcpy(filename, szBuff); | 
|---|
| [2] | 170 | return TRUE; | 
|---|
|  | 171 | } | 
|---|
|  | 172 | } | 
|---|
|  | 173 | return FALSE; | 
|---|
|  | 174 | } | 
|---|
|  | 175 |  | 
|---|
| [551] | 176 | void SetTargetDir(HWND hwnd, BOOL justshow) | 
|---|
|  | 177 | { | 
|---|
| [2] | 178 |  | 
|---|
|  | 179 | char temp[CCHMAXPATH + 12]; | 
|---|
|  | 180 |  | 
|---|
| [551] | 181 | if (!justshow) { | 
|---|
|  | 182 | strcpy(temp, targetdir); | 
|---|
|  | 183 | if (WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 184 | hwnd, | 
|---|
|  | 185 | WalkTargetDlgProc, | 
|---|
|  | 186 | FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) { | 
|---|
|  | 187 | strcpy(targetdir, temp); | 
|---|
|  | 188 | if (!fChangeTarget) | 
|---|
|  | 189 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir); | 
|---|
| [2] | 190 | } | 
|---|
|  | 191 | else { | 
|---|
| [551] | 192 | if (*targetdir && | 
|---|
|  | 193 | saymsg(MB_YESNOCANCEL, | 
|---|
|  | 194 | hwnd, | 
|---|
|  | 195 | GetPString(IDS_CLEARTARGETTITLETEXT), | 
|---|
|  | 196 | "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) { | 
|---|
|  | 197 | *targetdir = 0; | 
|---|
|  | 198 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL); | 
|---|
| [2] | 199 | } | 
|---|
|  | 200 | } | 
|---|
|  | 201 | } | 
|---|
|  | 202 |  | 
|---|
| [551] | 203 | if (hwndBack) { | 
|---|
|  | 204 | if (fShowTarget) | 
|---|
| [2] | 205 | sprintf(temp, | 
|---|
| [551] | 206 | "%s%s%s%s", | 
|---|
|  | 207 | GetPString(IDS_TARGETDIRTITLETEXT), | 
|---|
|  | 208 | (*targetdir) ? "" : "<", | 
|---|
|  | 209 | (*targetdir) ? | 
|---|
|  | 210 | targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">"); | 
|---|
| [2] | 211 | else | 
|---|
|  | 212 | *temp = 0; | 
|---|
| [551] | 213 | WinSetWindowText(hwndBack, temp); | 
|---|
| [2] | 214 | } | 
|---|
|  | 215 | } | 
|---|