| [907] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: mkdir.c 1438 2009-06-28 20:47:00Z gyoung $ | 
|---|
|  | 5 |  | 
|---|
|  | 6 | Make directory dialog | 
|---|
|  | 7 |  | 
|---|
|  | 8 | Copyright (c) 1993-97 M. Kimes | 
|---|
| [1348] | 9 | Copyright (c) 2004, 2008 Steven H.Levine | 
|---|
| [907] | 10 |  | 
|---|
|  | 11 | 01 Aug 04 SHL Baseline | 
|---|
| [985] | 12 | 29 Feb 08 GKY Refactor global command line variables to notebook.h | 
|---|
| [1104] | 13 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory | 
|---|
| [1358] | 14 | 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis | 
|---|
| [1438] | 15 | 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code. | 
|---|
| [907] | 16 |  | 
|---|
|  | 17 | ***********************************************************************/ | 
|---|
|  | 18 |  | 
|---|
|  | 19 | #include <string.h> | 
|---|
|  | 20 | #include <ctype.h> | 
|---|
|  | 21 |  | 
|---|
| [2] | 22 | #define INCL_DOSERRORS | 
|---|
|  | 23 | #define INCL_WIN | 
|---|
| [907] | 24 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| [2] | 25 |  | 
|---|
| [1187] | 26 | #include "fm3dll.h" | 
|---|
| [1225] | 27 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
|  | 28 | #include "mkdir.h" | 
|---|
| [1210] | 29 | #include "common.h"                     // Data declaration(s) | 
|---|
|  | 30 | #include "init.h"                       // Data declaration(s) | 
|---|
|  | 31 | #include "info.h"                       // Data declaration(s) | 
|---|
|  | 32 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
| [2] | 33 | #include "fm3dlg.h" | 
|---|
|  | 34 | #include "fm3str.h" | 
|---|
| [907] | 35 | #include "errutil.h"                    // Dos_Error... | 
|---|
|  | 36 | #include "strutil.h"                    // GetPString | 
|---|
| [985] | 37 | #include "notebook.h"                   // targetdirectoy | 
|---|
| [1163] | 38 | #include "walkem.h"                     // WalkTargetDlgProc | 
|---|
| [1187] | 39 | #include "misc.h"                       // Broadcast | 
|---|
|  | 40 | #include "valid.h"                      // IsFullName | 
|---|
|  | 41 | #include "dirs.h"                       // save_dir2 | 
|---|
|  | 42 | #include "input.h"                      // InputDlgProc | 
|---|
| [1438] | 43 | #include "pathutil.h"                   // AddBackslashToPath | 
|---|
| [2] | 44 |  | 
|---|
| [1210] | 45 | // Data definitions | 
|---|
|  | 46 | #pragma data_seg(GLOBAL2) | 
|---|
|  | 47 | CHAR targetdir[CCHMAXPATH]; | 
|---|
|  | 48 |  | 
|---|
| [1354] | 49 | //static PSZ pszSrcFile = __FILE__; | 
|---|
| [1348] | 50 |  | 
|---|
| [551] | 51 | APIRET MassMkdir(HWND hwndClient, CHAR * dir) | 
|---|
|  | 52 | { | 
|---|
|  | 53 | APIRET last, was = 0; | 
|---|
|  | 54 | CHAR *p; | 
|---|
|  | 55 | CHAR s[CCHMAXPATH]; | 
|---|
| [2] | 56 |  | 
|---|
| [551] | 57 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s))) | 
|---|
|  | 58 | strcpy(s, dir); | 
|---|
| [2] | 59 | p = s; | 
|---|
| [551] | 60 | while (*p) { | 
|---|
|  | 61 | if (*p == '/') | 
|---|
| [2] | 62 | *p = '\\'; | 
|---|
|  | 63 | p++; | 
|---|
|  | 64 | } | 
|---|
|  | 65 | p = s; | 
|---|
|  | 66 | do { | 
|---|
| [551] | 67 | p = strchr(p, '\\'); | 
|---|
|  | 68 | if (p && p > s && *(p - 1) == ':') | 
|---|
|  | 69 | p = strchr(p + 1, '\\'); | 
|---|
|  | 70 | if (p && *p) { | 
|---|
| [2] | 71 | *p = 0; | 
|---|
|  | 72 | was = 1; | 
|---|
|  | 73 | } | 
|---|
|  | 74 | else | 
|---|
|  | 75 | was = 0; | 
|---|
| [551] | 76 | last = DosCreateDir(s, NULL); | 
|---|
| [1348] | 77 | if (!last) { | 
|---|
| [551] | 78 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID); | 
|---|
| [1354] | 79 | //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s); | 
|---|
| [1348] | 80 | } | 
|---|
| [551] | 81 | else if (last == ERROR_ACCESS_DENIED) { | 
|---|
|  | 82 | if (!IsFile(s)) | 
|---|
|  | 83 | last = 0; | 
|---|
| [2] | 84 | } | 
|---|
| [551] | 85 | if (was) { | 
|---|
| [2] | 86 | *p = '\\'; | 
|---|
|  | 87 | p++; | 
|---|
|  | 88 | } | 
|---|
|  | 89 | } | 
|---|
| [551] | 90 | while (p && *p); | 
|---|
| [2] | 91 | return last; | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
| [551] | 94 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags) | 
|---|
|  | 95 | { | 
|---|
| [2] | 96 |  | 
|---|
|  | 97 | /* | 
|---|
|  | 98 | * bitmapped flags: | 
|---|
|  | 99 | * 1 = don't ask to create if non-existent | 
|---|
|  | 100 | */ | 
|---|
|  | 101 |  | 
|---|
| [551] | 102 | CHAR s[CCHMAXPATH], *p; | 
|---|
|  | 103 | APIRET ret = 0, error; | 
|---|
|  | 104 | INT isfile; | 
|---|
| [1354] | 105 | BOOL fResetVerify = FALSE; | 
|---|
| [2] | 106 |  | 
|---|
| [551] | 107 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s))) | 
|---|
|  | 108 | strcpy(s, dir); | 
|---|
|  | 109 | while ((p = strchr(s, '/')) != NULL) | 
|---|
| [2] | 110 | *p = '\\'; | 
|---|
| [551] | 111 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\') | 
|---|
| [2] | 112 | s[strlen(s) - 1] = 0; | 
|---|
| [551] | 113 | if (IsFullName(s)) { | 
|---|
|  | 114 | if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) { | 
|---|
|  | 115 | if (!(flags & 1)) | 
|---|
|  | 116 | saymsg(MB_CANCEL, | 
|---|
|  | 117 | hwnd, | 
|---|
|  | 118 | GetPString(IDS_NOPETEXT), | 
|---|
|  | 119 | GetPString(IDS_DRIVEISTEXT), | 
|---|
|  | 120 | toupper(*s), | 
|---|
|  | 121 | ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ? | 
|---|
|  | 122 | GetPString(IDS_BEINGIGNOREDTEXT) : | 
|---|
|  | 123 | GetPString(IDS_INVALIDTEXT)); | 
|---|
| [2] | 124 | return -5; | 
|---|
|  | 125 | } | 
|---|
|  | 126 | } | 
|---|
|  | 127 | isfile = IsFile(s); | 
|---|
| [551] | 128 | if (isfile == -1) { | 
|---|
|  | 129 | if (IsFullName(s)) { | 
|---|
|  | 130 | if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) { | 
|---|
|  | 131 | if (!(flags & 1)) | 
|---|
|  | 132 | saymsg(MB_CANCEL, | 
|---|
|  | 133 | hwnd, | 
|---|
|  | 134 | GetPString(IDS_NOPETEXT), | 
|---|
|  | 135 | GetPString(IDS_DRIVEISTEXT), | 
|---|
|  | 136 | toupper(*s), GetPString(IDS_NOWRITETEXT)); | 
|---|
|  | 137 | return -4; | 
|---|
| [2] | 138 | } | 
|---|
|  | 139 | } | 
|---|
| [551] | 140 | if (!(flags & 1)) { | 
|---|
|  | 141 | if (saymsg(MB_YESNO, | 
|---|
|  | 142 | hwnd, | 
|---|
|  | 143 | GetPString(IDS_CONFIRMTEXT), | 
|---|
|  | 144 | GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES) | 
|---|
|  | 145 | return -3; | 
|---|
| [2] | 146 | } | 
|---|
| [1354] | 147 | if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) { | 
|---|
|  | 148 | DosSetVerify(FALSE); | 
|---|
|  | 149 | fResetVerify = TRUE; | 
|---|
|  | 150 | } | 
|---|
|  | 151 | error = MassMkdir(hwnd, s); | 
|---|
|  | 152 | if (fResetVerify) { | 
|---|
|  | 153 | DosSetVerify(fVerify); | 
|---|
|  | 154 | fResetVerify = FALSE; | 
|---|
|  | 155 | } | 
|---|
| [551] | 156 | if (error) { | 
|---|
| [2] | 157 | Dos_Error(MB_CANCEL, | 
|---|
| [551] | 158 | error, | 
|---|
|  | 159 | hwnd, | 
|---|
|  | 160 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s); | 
|---|
| [2] | 161 | ret = -1; | 
|---|
|  | 162 | } | 
|---|
|  | 163 | } | 
|---|
| [551] | 164 | else if (isfile) { | 
|---|
| [2] | 165 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION, | 
|---|
| [551] | 166 | hwnd, | 
|---|
|  | 167 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s); | 
|---|
| [2] | 168 | ret = -2; | 
|---|
|  | 169 | } | 
|---|
|  | 170 | return ret; | 
|---|
|  | 171 | } | 
|---|
|  | 172 |  | 
|---|
| [551] | 173 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy) | 
|---|
|  | 174 | { | 
|---|
| [2] | 175 |  | 
|---|
|  | 176 | STRINGINPARMS sip; | 
|---|
| [551] | 177 | CHAR szBuff[CCHMAXPATH]; | 
|---|
|  | 178 | APIRET error; | 
|---|
| [1354] | 179 | BOOL fResetVerify = FALSE; | 
|---|
| [2] | 180 |  | 
|---|
|  | 181 | Over: | 
|---|
|  | 182 | sip.help = GetPString(IDS_MKDIRHELPTEXT); | 
|---|
|  | 183 | sip.ret = szBuff; | 
|---|
| [551] | 184 | if (filename) | 
|---|
|  | 185 | strcpy(szBuff, filename); | 
|---|
| [2] | 186 | else | 
|---|
| [1104] | 187 | strcpy(szBuff, pFM2SaveDirectory); | 
|---|
| [2] | 188 | MakeValidDir(szBuff); | 
|---|
| [1438] | 189 | AddBackslashToPath(szBuff); | 
|---|
|  | 190 | //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\') | 
|---|
|  | 191 | //  strcat(szBuff, "\\"); | 
|---|
| [2] | 192 | sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT); | 
|---|
|  | 193 | sip.inputlen = CCHMAXPATH - 1; | 
|---|
|  | 194 | sip.title = GetPString(IDS_MKDIRTITLETEXT); | 
|---|
| [551] | 195 | if (WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 196 | hwnd, | 
|---|
|  | 197 | InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) { | 
|---|
|  | 198 | if ((strchr(szBuff, '?') || | 
|---|
|  | 199 | strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) { | 
|---|
| [2] | 200 | saymsg(MB_ENTER | MB_ICONEXCLAMATION, | 
|---|
| [551] | 201 | hwnd, | 
|---|
|  | 202 | GetPString(IDS_ERRORTEXT), | 
|---|
|  | 203 | GetPString(IDS_DIRNAMEERRORTEXT), szBuff); | 
|---|
| [2] | 204 | goto Over; | 
|---|
|  | 205 | } | 
|---|
| [1354] | 206 | if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) { | 
|---|
|  | 207 | DosSetVerify(FALSE); | 
|---|
|  | 208 | fResetVerify = TRUE; | 
|---|
|  | 209 | } | 
|---|
| [551] | 210 | error = MassMkdir(hwnd, szBuff); | 
|---|
| [1354] | 211 | if (fResetVerify) { | 
|---|
|  | 212 | DosSetVerify(fVerify); | 
|---|
|  | 213 | fResetVerify = FALSE; | 
|---|
|  | 214 | } | 
|---|
| [551] | 215 | if (error) | 
|---|
| [2] | 216 | Dos_Error(MB_ENTER, | 
|---|
| [551] | 217 | error, | 
|---|
|  | 218 | hwnd, | 
|---|
|  | 219 | __FILE__, | 
|---|
|  | 220 | __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff); | 
|---|
| [2] | 221 | else { | 
|---|
| [551] | 222 | if (copy && filename) | 
|---|
|  | 223 | strcpy(filename, szBuff); | 
|---|
| [2] | 224 | return TRUE; | 
|---|
|  | 225 | } | 
|---|
|  | 226 | } | 
|---|
|  | 227 | return FALSE; | 
|---|
|  | 228 | } | 
|---|
|  | 229 |  | 
|---|
| [551] | 230 | void SetTargetDir(HWND hwnd, BOOL justshow) | 
|---|
|  | 231 | { | 
|---|
| [2] | 232 |  | 
|---|
|  | 233 | char temp[CCHMAXPATH + 12]; | 
|---|
|  | 234 |  | 
|---|
| [551] | 235 | if (!justshow) { | 
|---|
|  | 236 | strcpy(temp, targetdir); | 
|---|
|  | 237 | if (WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 238 | hwnd, | 
|---|
|  | 239 | WalkTargetDlgProc, | 
|---|
|  | 240 | FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) { | 
|---|
|  | 241 | strcpy(targetdir, temp); | 
|---|
|  | 242 | if (!fChangeTarget) | 
|---|
|  | 243 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir); | 
|---|
| [2] | 244 | } | 
|---|
|  | 245 | else { | 
|---|
| [551] | 246 | if (*targetdir && | 
|---|
|  | 247 | saymsg(MB_YESNOCANCEL, | 
|---|
|  | 248 | hwnd, | 
|---|
|  | 249 | GetPString(IDS_CLEARTARGETTITLETEXT), | 
|---|
| [1402] | 250 | GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) { | 
|---|
| [551] | 251 | *targetdir = 0; | 
|---|
|  | 252 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL); | 
|---|
| [2] | 253 | } | 
|---|
|  | 254 | } | 
|---|
|  | 255 | } | 
|---|
|  | 256 |  | 
|---|
| [551] | 257 | if (hwndBack) { | 
|---|
|  | 258 | if (fShowTarget) | 
|---|
| [2] | 259 | sprintf(temp, | 
|---|
| [551] | 260 | "%s%s%s%s", | 
|---|
|  | 261 | GetPString(IDS_TARGETDIRTITLETEXT), | 
|---|
| [1438] | 262 | (*targetdir) ? NullStr : "<", | 
|---|
| [551] | 263 | (*targetdir) ? | 
|---|
| [1438] | 264 | targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">"); | 
|---|
| [2] | 265 | else | 
|---|
|  | 266 | *temp = 0; | 
|---|
| [551] | 267 | WinSetWindowText(hwndBack, temp); | 
|---|
| [2] | 268 | } | 
|---|
|  | 269 | } | 
|---|
| [1316] | 270 |  | 
|---|
|  | 271 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir) | 
|---|