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