[907] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: mkdir.c 1673 2012-12-30 18:51:01Z 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.
|
---|
[1545] | 16 | 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
|
---|
[907] | 17 |
|
---|
| 18 | ***********************************************************************/
|
---|
| 19 |
|
---|
| 20 | #include <string.h>
|
---|
| 21 | #include <ctype.h>
|
---|
| 22 |
|
---|
[2] | 23 | #define INCL_DOSERRORS
|
---|
| 24 | #define INCL_WIN
|
---|
[907] | 25 | #define INCL_LONGLONG // dircnrs.h
|
---|
[2] | 26 |
|
---|
[1187] | 27 | #include "fm3dll.h"
|
---|
[1225] | 28 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
| 29 | #include "mkdir.h"
|
---|
[1210] | 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)
|
---|
[2] | 34 | #include "fm3dlg.h"
|
---|
| 35 | #include "fm3str.h"
|
---|
[907] | 36 | #include "errutil.h" // Dos_Error...
|
---|
| 37 | #include "strutil.h" // GetPString
|
---|
[985] | 38 | #include "notebook.h" // targetdirectoy
|
---|
[1163] | 39 | #include "walkem.h" // WalkTargetDlgProc
|
---|
[1187] | 40 | #include "misc.h" // Broadcast
|
---|
| 41 | #include "valid.h" // IsFullName
|
---|
| 42 | #include "dirs.h" // save_dir2
|
---|
| 43 | #include "input.h" // InputDlgProc
|
---|
[1438] | 44 | #include "pathutil.h" // AddBackslashToPath
|
---|
[2] | 45 |
|
---|
[1210] | 46 | // Data definitions
|
---|
| 47 | #pragma data_seg(GLOBAL2)
|
---|
| 48 | CHAR targetdir[CCHMAXPATH];
|
---|
| 49 |
|
---|
[1354] | 50 | //static PSZ pszSrcFile = __FILE__;
|
---|
[1348] | 51 |
|
---|
[551] | 52 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
|
---|
| 53 | {
|
---|
| 54 | APIRET last, was = 0;
|
---|
| 55 | CHAR *p;
|
---|
| 56 | CHAR s[CCHMAXPATH];
|
---|
[2] | 57 |
|
---|
[551] | 58 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
| 59 | strcpy(s, dir);
|
---|
[1545] | 60 | ForwardslashToBackslash(s);
|
---|
[2] | 61 | p = s;
|
---|
| 62 | do {
|
---|
[551] | 63 | p = strchr(p, '\\');
|
---|
| 64 | if (p && p > s && *(p - 1) == ':')
|
---|
| 65 | p = strchr(p + 1, '\\');
|
---|
| 66 | if (p && *p) {
|
---|
[2] | 67 | *p = 0;
|
---|
| 68 | was = 1;
|
---|
| 69 | }
|
---|
| 70 | else
|
---|
| 71 | was = 0;
|
---|
[551] | 72 | last = DosCreateDir(s, NULL);
|
---|
[1348] | 73 | if (!last) {
|
---|
[551] | 74 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
|
---|
[1354] | 75 | //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
|
---|
[1348] | 76 | }
|
---|
[551] | 77 | else if (last == ERROR_ACCESS_DENIED) {
|
---|
| 78 | if (!IsFile(s))
|
---|
| 79 | last = 0;
|
---|
[2] | 80 | }
|
---|
[551] | 81 | if (was) {
|
---|
[2] | 82 | *p = '\\';
|
---|
| 83 | p++;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
[551] | 86 | while (p && *p);
|
---|
[2] | 87 | return last;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[551] | 90 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
|
---|
| 91 | {
|
---|
[2] | 92 |
|
---|
[1673] | 93 | /**
|
---|
[2] | 94 | * bitmapped flags:
|
---|
| 95 | * 1 = don't ask to create if non-existent
|
---|
| 96 | */
|
---|
| 97 |
|
---|
[551] | 98 | CHAR s[CCHMAXPATH], *p;
|
---|
| 99 | APIRET ret = 0, error;
|
---|
| 100 | INT isfile;
|
---|
[1354] | 101 | BOOL fResetVerify = FALSE;
|
---|
[2] | 102 |
|
---|
[551] | 103 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
| 104 | strcpy(s, dir);
|
---|
| 105 | while ((p = strchr(s, '/')) != NULL)
|
---|
[2] | 106 | *p = '\\';
|
---|
[551] | 107 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
|
---|
[2] | 108 | s[strlen(s) - 1] = 0;
|
---|
[551] | 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));
|
---|
[2] | 120 | return -5;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | isfile = IsFile(s);
|
---|
[551] | 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;
|
---|
[2] | 134 | }
|
---|
| 135 | }
|
---|
[551] | 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;
|
---|
[2] | 142 | }
|
---|
[1354] | 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 | }
|
---|
[551] | 152 | if (error) {
|
---|
[2] | 153 | Dos_Error(MB_CANCEL,
|
---|
[551] | 154 | error,
|
---|
| 155 | hwnd,
|
---|
| 156 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
|
---|
[2] | 157 | ret = -1;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
[551] | 160 | else if (isfile) {
|
---|
[2] | 161 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
[551] | 162 | hwnd,
|
---|
| 163 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
|
---|
[2] | 164 | ret = -2;
|
---|
| 165 | }
|
---|
| 166 | return ret;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[551] | 169 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
|
---|
| 170 | {
|
---|
[2] | 171 |
|
---|
| 172 | STRINGINPARMS sip;
|
---|
[551] | 173 | CHAR szBuff[CCHMAXPATH];
|
---|
| 174 | APIRET error;
|
---|
[1354] | 175 | BOOL fResetVerify = FALSE;
|
---|
[2] | 176 |
|
---|
| 177 | Over:
|
---|
| 178 | sip.help = GetPString(IDS_MKDIRHELPTEXT);
|
---|
| 179 | sip.ret = szBuff;
|
---|
[551] | 180 | if (filename)
|
---|
| 181 | strcpy(szBuff, filename);
|
---|
[2] | 182 | else
|
---|
[1104] | 183 | strcpy(szBuff, pFM2SaveDirectory);
|
---|
[2] | 184 | MakeValidDir(szBuff);
|
---|
[1438] | 185 | AddBackslashToPath(szBuff);
|
---|
| 186 | //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
|
---|
| 187 | // strcat(szBuff, "\\");
|
---|
[2] | 188 | sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
|
---|
| 189 | sip.inputlen = CCHMAXPATH - 1;
|
---|
| 190 | sip.title = GetPString(IDS_MKDIRTITLETEXT);
|
---|
[551] | 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)) {
|
---|
[2] | 196 | saymsg(MB_ENTER | MB_ICONEXCLAMATION,
|
---|
[551] | 197 | hwnd,
|
---|
| 198 | GetPString(IDS_ERRORTEXT),
|
---|
| 199 | GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
|
---|
[2] | 200 | goto Over;
|
---|
| 201 | }
|
---|
[1354] | 202 | if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
|
---|
| 203 | DosSetVerify(FALSE);
|
---|
| 204 | fResetVerify = TRUE;
|
---|
| 205 | }
|
---|
[551] | 206 | error = MassMkdir(hwnd, szBuff);
|
---|
[1354] | 207 | if (fResetVerify) {
|
---|
| 208 | DosSetVerify(fVerify);
|
---|
| 209 | fResetVerify = FALSE;
|
---|
| 210 | }
|
---|
[551] | 211 | if (error)
|
---|
[2] | 212 | Dos_Error(MB_ENTER,
|
---|
[551] | 213 | error,
|
---|
| 214 | hwnd,
|
---|
| 215 | __FILE__,
|
---|
| 216 | __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
|
---|
[2] | 217 | else {
|
---|
[551] | 218 | if (copy && filename)
|
---|
| 219 | strcpy(filename, szBuff);
|
---|
[2] | 220 | return TRUE;
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | return FALSE;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[551] | 226 | void SetTargetDir(HWND hwnd, BOOL justshow)
|
---|
| 227 | {
|
---|
[2] | 228 |
|
---|
| 229 | char temp[CCHMAXPATH + 12];
|
---|
| 230 |
|
---|
[551] | 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);
|
---|
[2] | 240 | }
|
---|
| 241 | else {
|
---|
[551] | 242 | if (*targetdir &&
|
---|
| 243 | saymsg(MB_YESNOCANCEL,
|
---|
| 244 | hwnd,
|
---|
| 245 | GetPString(IDS_CLEARTARGETTITLETEXT),
|
---|
[1402] | 246 | GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
|
---|
[551] | 247 | *targetdir = 0;
|
---|
| 248 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
|
---|
[2] | 249 | }
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[551] | 253 | if (hwndBack) {
|
---|
| 254 | if (fShowTarget)
|
---|
[2] | 255 | sprintf(temp,
|
---|
[551] | 256 | "%s%s%s%s",
|
---|
| 257 | GetPString(IDS_TARGETDIRTITLETEXT),
|
---|
[1438] | 258 | (*targetdir) ? NullStr : "<",
|
---|
[551] | 259 | (*targetdir) ?
|
---|
[1438] | 260 | targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
|
---|
[2] | 261 | else
|
---|
| 262 | *temp = 0;
|
---|
[551] | 263 | WinSetWindowText(hwndBack, temp);
|
---|
[2] | 264 | }
|
---|
| 265 | }
|
---|
[1316] | 266 |
|
---|
| 267 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
|
---|