| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: mkdir.c 1545 2010-10-23 22:00:47Z 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 |
|
|---|
| 18 | ***********************************************************************/
|
|---|
| 19 |
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 | #include <ctype.h>
|
|---|
| 22 |
|
|---|
| 23 | #define INCL_DOSERRORS
|
|---|
| 24 | #define INCL_WIN
|
|---|
| 25 | #define INCL_LONGLONG // dircnrs.h
|
|---|
| 26 |
|
|---|
| 27 | #include "fm3dll.h"
|
|---|
| 28 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
|---|
| 29 | #include "mkdir.h"
|
|---|
| 30 | #include "common.h" // Data declaration(s)
|
|---|
| 31 | #include "init.h" // Data declaration(s)
|
|---|
| 32 | #include "info.h" // Data declaration(s)
|
|---|
| 33 | #include "mainwnd.h" // Data declaration(s)
|
|---|
| 34 | #include "fm3dlg.h"
|
|---|
| 35 | #include "fm3str.h"
|
|---|
| 36 | #include "errutil.h" // Dos_Error...
|
|---|
| 37 | #include "strutil.h" // GetPString
|
|---|
| 38 | #include "notebook.h" // targetdirectoy
|
|---|
| 39 | #include "walkem.h" // WalkTargetDlgProc
|
|---|
| 40 | #include "misc.h" // Broadcast
|
|---|
| 41 | #include "valid.h" // IsFullName
|
|---|
| 42 | #include "dirs.h" // save_dir2
|
|---|
| 43 | #include "input.h" // InputDlgProc
|
|---|
| 44 | #include "pathutil.h" // AddBackslashToPath
|
|---|
| 45 |
|
|---|
| 46 | // Data definitions
|
|---|
| 47 | #pragma data_seg(GLOBAL2)
|
|---|
| 48 | CHAR targetdir[CCHMAXPATH];
|
|---|
| 49 |
|
|---|
| 50 | //static PSZ pszSrcFile = __FILE__;
|
|---|
| 51 |
|
|---|
| 52 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
|
|---|
| 53 | {
|
|---|
| 54 | APIRET last, was = 0;
|
|---|
| 55 | CHAR *p;
|
|---|
| 56 | CHAR s[CCHMAXPATH];
|
|---|
| 57 |
|
|---|
| 58 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
|---|
| 59 | strcpy(s, dir);
|
|---|
| 60 | ForwardslashToBackslash(s);
|
|---|
| 61 | p = s;
|
|---|
| 62 | do {
|
|---|
| 63 | p = strchr(p, '\\');
|
|---|
| 64 | if (p && p > s && *(p - 1) == ':')
|
|---|
| 65 | p = strchr(p + 1, '\\');
|
|---|
| 66 | if (p && *p) {
|
|---|
| 67 | *p = 0;
|
|---|
| 68 | was = 1;
|
|---|
| 69 | }
|
|---|
| 70 | else
|
|---|
| 71 | was = 0;
|
|---|
| 72 | last = DosCreateDir(s, NULL);
|
|---|
| 73 | if (!last) {
|
|---|
| 74 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
|
|---|
| 75 | //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
|
|---|
| 76 | }
|
|---|
| 77 | else if (last == ERROR_ACCESS_DENIED) {
|
|---|
| 78 | if (!IsFile(s))
|
|---|
| 79 | last = 0;
|
|---|
| 80 | }
|
|---|
| 81 | if (was) {
|
|---|
| 82 | *p = '\\';
|
|---|
| 83 | p++;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | while (p && *p);
|
|---|
| 87 | return last;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
|
|---|
| 91 | {
|
|---|
| 92 |
|
|---|
| 93 | /*
|
|---|
| 94 | * bitmapped flags:
|
|---|
| 95 | * 1 = don't ask to create if non-existent
|
|---|
| 96 | */
|
|---|
| 97 |
|
|---|
| 98 | CHAR s[CCHMAXPATH], *p;
|
|---|
| 99 | APIRET ret = 0, error;
|
|---|
| 100 | INT isfile;
|
|---|
| 101 | BOOL fResetVerify = FALSE;
|
|---|
| 102 |
|
|---|
| 103 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
|---|
| 104 | strcpy(s, dir);
|
|---|
| 105 | while ((p = strchr(s, '/')) != NULL)
|
|---|
| 106 | *p = '\\';
|
|---|
| 107 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
|
|---|
| 108 | s[strlen(s) - 1] = 0;
|
|---|
| 109 | if (IsFullName(s)) {
|
|---|
| 110 | if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
|
|---|
| 111 | if (!(flags & 1))
|
|---|
| 112 | saymsg(MB_CANCEL,
|
|---|
| 113 | hwnd,
|
|---|
| 114 | GetPString(IDS_NOPETEXT),
|
|---|
| 115 | GetPString(IDS_DRIVEISTEXT),
|
|---|
| 116 | toupper(*s),
|
|---|
| 117 | ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
|
|---|
| 118 | GetPString(IDS_BEINGIGNOREDTEXT) :
|
|---|
| 119 | GetPString(IDS_INVALIDTEXT));
|
|---|
| 120 | return -5;
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 | isfile = IsFile(s);
|
|---|
| 124 | if (isfile == -1) {
|
|---|
| 125 | if (IsFullName(s)) {
|
|---|
| 126 | if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
|
|---|
| 127 | if (!(flags & 1))
|
|---|
| 128 | saymsg(MB_CANCEL,
|
|---|
| 129 | hwnd,
|
|---|
| 130 | GetPString(IDS_NOPETEXT),
|
|---|
| 131 | GetPString(IDS_DRIVEISTEXT),
|
|---|
| 132 | toupper(*s), GetPString(IDS_NOWRITETEXT));
|
|---|
| 133 | return -4;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 | if (!(flags & 1)) {
|
|---|
| 137 | if (saymsg(MB_YESNO,
|
|---|
| 138 | hwnd,
|
|---|
| 139 | GetPString(IDS_CONFIRMTEXT),
|
|---|
| 140 | GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
|
|---|
| 141 | return -3;
|
|---|
| 142 | }
|
|---|
| 143 | if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
|
|---|
| 144 | DosSetVerify(FALSE);
|
|---|
| 145 | fResetVerify = TRUE;
|
|---|
| 146 | }
|
|---|
| 147 | error = MassMkdir(hwnd, s);
|
|---|
| 148 | if (fResetVerify) {
|
|---|
| 149 | DosSetVerify(fVerify);
|
|---|
| 150 | fResetVerify = FALSE;
|
|---|
| 151 | }
|
|---|
| 152 | if (error) {
|
|---|
| 153 | Dos_Error(MB_CANCEL,
|
|---|
| 154 | error,
|
|---|
| 155 | hwnd,
|
|---|
| 156 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
|
|---|
| 157 | ret = -1;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | else if (isfile) {
|
|---|
| 161 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
|---|
| 162 | hwnd,
|
|---|
| 163 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
|
|---|
| 164 | ret = -2;
|
|---|
| 165 | }
|
|---|
| 166 | return ret;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
|
|---|
| 170 | {
|
|---|
| 171 |
|
|---|
| 172 | STRINGINPARMS sip;
|
|---|
| 173 | CHAR szBuff[CCHMAXPATH];
|
|---|
| 174 | APIRET error;
|
|---|
| 175 | BOOL fResetVerify = FALSE;
|
|---|
| 176 |
|
|---|
| 177 | Over:
|
|---|
| 178 | sip.help = GetPString(IDS_MKDIRHELPTEXT);
|
|---|
| 179 | sip.ret = szBuff;
|
|---|
| 180 | if (filename)
|
|---|
| 181 | strcpy(szBuff, filename);
|
|---|
| 182 | else
|
|---|
| 183 | strcpy(szBuff, pFM2SaveDirectory);
|
|---|
| 184 | MakeValidDir(szBuff);
|
|---|
| 185 | AddBackslashToPath(szBuff);
|
|---|
| 186 | //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
|
|---|
| 187 | // strcat(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 | void SetTargetDir(HWND hwnd, BOOL justshow)
|
|---|
| 227 | {
|
|---|
| 228 |
|
|---|
| 229 | char temp[CCHMAXPATH + 12];
|
|---|
| 230 |
|
|---|
| 231 | if (!justshow) {
|
|---|
| 232 | strcpy(temp, targetdir);
|
|---|
| 233 | if (WinDlgBox(HWND_DESKTOP,
|
|---|
| 234 | hwnd,
|
|---|
| 235 | WalkTargetDlgProc,
|
|---|
| 236 | FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
|
|---|
| 237 | strcpy(targetdir, temp);
|
|---|
| 238 | if (!fChangeTarget)
|
|---|
| 239 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
|
|---|
| 240 | }
|
|---|
| 241 | else {
|
|---|
| 242 | if (*targetdir &&
|
|---|
| 243 | saymsg(MB_YESNOCANCEL,
|
|---|
| 244 | hwnd,
|
|---|
| 245 | GetPString(IDS_CLEARTARGETTITLETEXT),
|
|---|
| 246 | GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
|
|---|
| 247 | *targetdir = 0;
|
|---|
| 248 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | if (hwndBack) {
|
|---|
| 254 | if (fShowTarget)
|
|---|
| 255 | sprintf(temp,
|
|---|
| 256 | "%s%s%s%s",
|
|---|
| 257 | GetPString(IDS_TARGETDIRTITLETEXT),
|
|---|
| 258 | (*targetdir) ? NullStr : "<",
|
|---|
| 259 | (*targetdir) ?
|
|---|
| 260 | targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
|
|---|
| 261 | else
|
|---|
| 262 | *temp = 0;
|
|---|
| 263 | WinSetWindowText(hwndBack, temp);
|
|---|
| 264 | }
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
|
|---|