| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: mkdir.c 1358 2008-12-27 00:03:08Z 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 | 
 | 
|---|
| 16 | ***********************************************************************/
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <string.h>
 | 
|---|
| 19 | #include <ctype.h>
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #define INCL_DOSERRORS
 | 
|---|
| 22 | #define INCL_WIN
 | 
|---|
| 23 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "fm3dll.h"
 | 
|---|
| 26 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| 27 | #include "mkdir.h"
 | 
|---|
| 28 | #include "common.h"                     // Data declaration(s)
 | 
|---|
| 29 | #include "init.h"                       // Data declaration(s)
 | 
|---|
| 30 | #include "info.h"                       // Data declaration(s)
 | 
|---|
| 31 | #include "mainwnd.h"                    // Data declaration(s)
 | 
|---|
| 32 | #include "fm3dlg.h"
 | 
|---|
| 33 | #include "fm3str.h"
 | 
|---|
| 34 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 35 | #include "strutil.h"                    // GetPString
 | 
|---|
| 36 | #include "notebook.h"                   // targetdirectoy
 | 
|---|
| 37 | #include "walkem.h"                     // WalkTargetDlgProc
 | 
|---|
| 38 | #include "misc.h"                       // Broadcast
 | 
|---|
| 39 | #include "valid.h"                      // IsFullName
 | 
|---|
| 40 | #include "dirs.h"                       // save_dir2
 | 
|---|
| 41 | #include "input.h"                      // InputDlgProc
 | 
|---|
| 42 | 
 | 
|---|
| 43 | // Data definitions
 | 
|---|
| 44 | #pragma data_seg(GLOBAL2)
 | 
|---|
| 45 | CHAR targetdir[CCHMAXPATH];
 | 
|---|
| 46 | 
 | 
|---|
| 47 | //static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 48 | 
 | 
|---|
| 49 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
 | 
|---|
| 50 | {
 | 
|---|
| 51 |   APIRET last, was = 0;
 | 
|---|
| 52 |   CHAR *p;
 | 
|---|
| 53 |   CHAR s[CCHMAXPATH];
 | 
|---|
| 54 | 
 | 
|---|
| 55 |   if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
 | 
|---|
| 56 |     strcpy(s, dir);
 | 
|---|
| 57 |   p = s;
 | 
|---|
| 58 |   while (*p) {
 | 
|---|
| 59 |     if (*p == '/')
 | 
|---|
| 60 |       *p = '\\';
 | 
|---|
| 61 |     p++;
 | 
|---|
| 62 |   }
 | 
|---|
| 63 |   p = s;
 | 
|---|
| 64 |   do {
 | 
|---|
| 65 |     p = strchr(p, '\\');
 | 
|---|
| 66 |     if (p && p > s && *(p - 1) == ':')
 | 
|---|
| 67 |       p = strchr(p + 1, '\\');
 | 
|---|
| 68 |     if (p && *p) {
 | 
|---|
| 69 |       *p = 0;
 | 
|---|
| 70 |       was = 1;
 | 
|---|
| 71 |     }
 | 
|---|
| 72 |     else
 | 
|---|
| 73 |       was = 0;
 | 
|---|
| 74 |     last = DosCreateDir(s, NULL);
 | 
|---|
| 75 |     if (!last) {
 | 
|---|
| 76 |       Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
 | 
|---|
| 77 |       //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
 | 
|---|
| 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 |   if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
 | 
|---|
| 188 |     strcat(szBuff, "\\");
 | 
|---|
| 189 |   sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
 | 
|---|
| 190 |   sip.inputlen = CCHMAXPATH - 1;
 | 
|---|
| 191 |   sip.title = GetPString(IDS_MKDIRTITLETEXT);
 | 
|---|
| 192 |   if (WinDlgBox(HWND_DESKTOP,
 | 
|---|
| 193 |                 hwnd,
 | 
|---|
| 194 |                 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
 | 
|---|
| 195 |     if ((strchr(szBuff, '?') ||
 | 
|---|
| 196 |          strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
 | 
|---|
| 197 |       saymsg(MB_ENTER | MB_ICONEXCLAMATION,
 | 
|---|
| 198 |              hwnd,
 | 
|---|
| 199 |              GetPString(IDS_ERRORTEXT),
 | 
|---|
| 200 |              GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
 | 
|---|
| 201 |       goto Over;
 | 
|---|
| 202 |     }
 | 
|---|
| 203 |     if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
 | 
|---|
| 204 |       DosSetVerify(FALSE);
 | 
|---|
| 205 |       fResetVerify = TRUE;
 | 
|---|
| 206 |     }
 | 
|---|
| 207 |     error = MassMkdir(hwnd, szBuff);
 | 
|---|
| 208 |     if (fResetVerify) {
 | 
|---|
| 209 |       DosSetVerify(fVerify);
 | 
|---|
| 210 |       fResetVerify = FALSE;
 | 
|---|
| 211 |     }
 | 
|---|
| 212 |     if (error)
 | 
|---|
| 213 |       Dos_Error(MB_ENTER,
 | 
|---|
| 214 |                 error,
 | 
|---|
| 215 |                 hwnd,
 | 
|---|
| 216 |                 __FILE__,
 | 
|---|
| 217 |                 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
 | 
|---|
| 218 |     else {
 | 
|---|
| 219 |       if (copy && filename)
 | 
|---|
| 220 |         strcpy(filename, szBuff);
 | 
|---|
| 221 |       return TRUE;
 | 
|---|
| 222 |     }
 | 
|---|
| 223 |   }
 | 
|---|
| 224 |   return FALSE;
 | 
|---|
| 225 | }
 | 
|---|
| 226 | 
 | 
|---|
| 227 | void SetTargetDir(HWND hwnd, BOOL justshow)
 | 
|---|
| 228 | {
 | 
|---|
| 229 | 
 | 
|---|
| 230 |   char temp[CCHMAXPATH + 12];
 | 
|---|
| 231 | 
 | 
|---|
| 232 |   if (!justshow) {
 | 
|---|
| 233 |     strcpy(temp, targetdir);
 | 
|---|
| 234 |     if (WinDlgBox(HWND_DESKTOP,
 | 
|---|
| 235 |                   hwnd,
 | 
|---|
| 236 |                   WalkTargetDlgProc,
 | 
|---|
| 237 |                   FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
 | 
|---|
| 238 |       strcpy(targetdir, temp);
 | 
|---|
| 239 |       if (!fChangeTarget)
 | 
|---|
| 240 |         PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
 | 
|---|
| 241 |     }
 | 
|---|
| 242 |     else {
 | 
|---|
| 243 |       if (*targetdir &&
 | 
|---|
| 244 |           saymsg(MB_YESNOCANCEL,
 | 
|---|
| 245 |                  hwnd,
 | 
|---|
| 246 |                  GetPString(IDS_CLEARTARGETTITLETEXT),
 | 
|---|
| 247 |                  "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
 | 
|---|
| 248 |         *targetdir = 0;
 | 
|---|
| 249 |         PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
 | 
|---|
| 250 |       }
 | 
|---|
| 251 |     }
 | 
|---|
| 252 |   }
 | 
|---|
| 253 | 
 | 
|---|
| 254 |   if (hwndBack) {
 | 
|---|
| 255 |     if (fShowTarget)
 | 
|---|
| 256 |       sprintf(temp,
 | 
|---|
| 257 |               "%s%s%s%s",
 | 
|---|
| 258 |               GetPString(IDS_TARGETDIRTITLETEXT),
 | 
|---|
| 259 |               (*targetdir) ? "" : "<",
 | 
|---|
| 260 |               (*targetdir) ?
 | 
|---|
| 261 |               targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
 | 
|---|
| 262 |     else
 | 
|---|
| 263 |       *temp = 0;
 | 
|---|
| 264 |     WinSetWindowText(hwndBack, temp);
 | 
|---|
| 265 |   }
 | 
|---|
| 266 | }
 | 
|---|
| 267 | 
 | 
|---|
| 268 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
 | 
|---|