| [907] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: mkdir.c 907 2008-01-06 07:26:17Z stevenhl $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Make directory dialog
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 |   Copyright (c) 1993-97 M. Kimes
 | 
|---|
 | 9 |   Copyright (c) 2004, 2007 Steven H.Levine
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 |   01 Aug 04 SHL Baseline
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | ***********************************************************************/
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | #include <string.h>
 | 
|---|
 | 16 | #include <ctype.h>
 | 
|---|
 | 17 | 
 | 
|---|
| [2] | 18 | #define INCL_DOSERRORS
 | 
|---|
 | 19 | #define INCL_WIN
 | 
|---|
| [907] | 20 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| [2] | 21 | 
 | 
|---|
 | 22 | #include "fm3dlg.h"
 | 
|---|
 | 23 | #include "fm3str.h"
 | 
|---|
| [907] | 24 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
 | 25 | #include "strutil.h"                    // GetPString
 | 
|---|
 | 26 | #include "fm3dll.h"
 | 
|---|
| [2] | 27 | 
 | 
|---|
 | 28 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
 | 
|---|
 | 29 | 
 | 
|---|
| [551] | 30 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
 | 
|---|
 | 31 | {
 | 
|---|
 | 32 |   APIRET last, was = 0;
 | 
|---|
 | 33 |   CHAR *p;
 | 
|---|
 | 34 |   CHAR s[CCHMAXPATH];
 | 
|---|
| [2] | 35 | 
 | 
|---|
| [551] | 36 |   if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
 | 
|---|
 | 37 |     strcpy(s, dir);
 | 
|---|
| [2] | 38 |   p = s;
 | 
|---|
| [551] | 39 |   while (*p) {
 | 
|---|
 | 40 |     if (*p == '/')
 | 
|---|
| [2] | 41 |       *p = '\\';
 | 
|---|
 | 42 |     p++;
 | 
|---|
 | 43 |   }
 | 
|---|
 | 44 |   p = s;
 | 
|---|
 | 45 |   do {
 | 
|---|
| [551] | 46 |     p = strchr(p, '\\');
 | 
|---|
 | 47 |     if (p && p > s && *(p - 1) == ':')
 | 
|---|
 | 48 |       p = strchr(p + 1, '\\');
 | 
|---|
 | 49 |     if (p && *p) {
 | 
|---|
| [2] | 50 |       *p = 0;
 | 
|---|
 | 51 |       was = 1;
 | 
|---|
 | 52 |     }
 | 
|---|
 | 53 |     else
 | 
|---|
 | 54 |       was = 0;
 | 
|---|
| [551] | 55 |     last = DosCreateDir(s, NULL);
 | 
|---|
 | 56 |     if (!last)
 | 
|---|
 | 57 |       Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
 | 
|---|
 | 58 |     else if (last == ERROR_ACCESS_DENIED) {
 | 
|---|
 | 59 |       if (!IsFile(s))
 | 
|---|
 | 60 |         last = 0;
 | 
|---|
| [2] | 61 |     }
 | 
|---|
| [551] | 62 |     if (was) {
 | 
|---|
| [2] | 63 |       *p = '\\';
 | 
|---|
 | 64 |       p++;
 | 
|---|
 | 65 |     }
 | 
|---|
 | 66 |   }
 | 
|---|
| [551] | 67 |   while (p && *p);
 | 
|---|
| [2] | 68 |   return last;
 | 
|---|
 | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
| [551] | 71 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
 | 
|---|
 | 72 | {
 | 
|---|
| [2] | 73 | 
 | 
|---|
 | 74 |   /*
 | 
|---|
 | 75 |    * bitmapped flags:
 | 
|---|
 | 76 |    * 1 = don't ask to create if non-existent
 | 
|---|
 | 77 |    */
 | 
|---|
 | 78 | 
 | 
|---|
| [551] | 79 |   CHAR s[CCHMAXPATH], *p;
 | 
|---|
 | 80 |   APIRET ret = 0, error;
 | 
|---|
 | 81 |   INT isfile;
 | 
|---|
| [2] | 82 | 
 | 
|---|
| [551] | 83 |   if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
 | 
|---|
 | 84 |     strcpy(s, dir);
 | 
|---|
 | 85 |   while ((p = strchr(s, '/')) != NULL)
 | 
|---|
| [2] | 86 |     *p = '\\';
 | 
|---|
| [551] | 87 |   while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
 | 
|---|
| [2] | 88 |     s[strlen(s) - 1] = 0;
 | 
|---|
| [551] | 89 |   if (IsFullName(s)) {
 | 
|---|
 | 90 |     if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
 | 
|---|
 | 91 |       if (!(flags & 1))
 | 
|---|
 | 92 |         saymsg(MB_CANCEL,
 | 
|---|
 | 93 |                hwnd,
 | 
|---|
 | 94 |                GetPString(IDS_NOPETEXT),
 | 
|---|
 | 95 |                GetPString(IDS_DRIVEISTEXT),
 | 
|---|
 | 96 |                toupper(*s),
 | 
|---|
 | 97 |                ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
 | 
|---|
 | 98 |                GetPString(IDS_BEINGIGNOREDTEXT) :
 | 
|---|
 | 99 |                GetPString(IDS_INVALIDTEXT));
 | 
|---|
| [2] | 100 |       return -5;
 | 
|---|
 | 101 |     }
 | 
|---|
 | 102 |   }
 | 
|---|
 | 103 |   isfile = IsFile(s);
 | 
|---|
| [551] | 104 |   if (isfile == -1) {
 | 
|---|
 | 105 |     if (IsFullName(s)) {
 | 
|---|
 | 106 |       if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
 | 
|---|
 | 107 |         if (!(flags & 1))
 | 
|---|
 | 108 |           saymsg(MB_CANCEL,
 | 
|---|
 | 109 |                  hwnd,
 | 
|---|
 | 110 |                  GetPString(IDS_NOPETEXT),
 | 
|---|
 | 111 |                  GetPString(IDS_DRIVEISTEXT),
 | 
|---|
 | 112 |                  toupper(*s), GetPString(IDS_NOWRITETEXT));
 | 
|---|
 | 113 |         return -4;
 | 
|---|
| [2] | 114 |       }
 | 
|---|
 | 115 |     }
 | 
|---|
| [551] | 116 |     if (!(flags & 1)) {
 | 
|---|
 | 117 |       if (saymsg(MB_YESNO,
 | 
|---|
 | 118 |                  hwnd,
 | 
|---|
 | 119 |                  GetPString(IDS_CONFIRMTEXT),
 | 
|---|
 | 120 |                  GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
 | 
|---|
 | 121 |         return -3;
 | 
|---|
| [2] | 122 |     }
 | 
|---|
| [551] | 123 |     error = MassMkdir(hwndClient, s);
 | 
|---|
 | 124 |     if (error) {
 | 
|---|
| [2] | 125 |       Dos_Error(MB_CANCEL,
 | 
|---|
| [551] | 126 |                 error,
 | 
|---|
 | 127 |                 hwnd,
 | 
|---|
 | 128 |                 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
 | 
|---|
| [2] | 129 |       ret = -1;
 | 
|---|
 | 130 |     }
 | 
|---|
 | 131 |   }
 | 
|---|
| [551] | 132 |   else if (isfile) {
 | 
|---|
| [2] | 133 |     saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
 | 
|---|
| [551] | 134 |            hwnd,
 | 
|---|
 | 135 |            GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
 | 
|---|
| [2] | 136 |     ret = -2;
 | 
|---|
 | 137 |   }
 | 
|---|
 | 138 |   return ret;
 | 
|---|
 | 139 | }
 | 
|---|
 | 140 | 
 | 
|---|
| [551] | 141 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
 | 
|---|
 | 142 | {
 | 
|---|
| [2] | 143 | 
 | 
|---|
 | 144 |   STRINGINPARMS sip;
 | 
|---|
| [551] | 145 |   CHAR szBuff[CCHMAXPATH];
 | 
|---|
 | 146 |   APIRET error;
 | 
|---|
| [2] | 147 | 
 | 
|---|
 | 148 | Over:
 | 
|---|
 | 149 |   sip.help = GetPString(IDS_MKDIRHELPTEXT);
 | 
|---|
 | 150 |   sip.ret = szBuff;
 | 
|---|
| [551] | 151 |   if (filename)
 | 
|---|
 | 152 |     strcpy(szBuff, filename);
 | 
|---|
| [2] | 153 |   else
 | 
|---|
 | 154 |     save_dir2(szBuff);
 | 
|---|
 | 155 |   MakeValidDir(szBuff);
 | 
|---|
| [551] | 156 |   if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
 | 
|---|
 | 157 |     strcat(szBuff, "\\");
 | 
|---|
| [2] | 158 |   sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
 | 
|---|
 | 159 |   sip.inputlen = CCHMAXPATH - 1;
 | 
|---|
 | 160 |   sip.title = GetPString(IDS_MKDIRTITLETEXT);
 | 
|---|
| [551] | 161 |   if (WinDlgBox(HWND_DESKTOP,
 | 
|---|
 | 162 |                 hwnd,
 | 
|---|
 | 163 |                 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
 | 
|---|
 | 164 |     if ((strchr(szBuff, '?') ||
 | 
|---|
 | 165 |          strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
 | 
|---|
| [2] | 166 |       saymsg(MB_ENTER | MB_ICONEXCLAMATION,
 | 
|---|
| [551] | 167 |              hwnd,
 | 
|---|
 | 168 |              GetPString(IDS_ERRORTEXT),
 | 
|---|
 | 169 |              GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
 | 
|---|
| [2] | 170 |       goto Over;
 | 
|---|
 | 171 |     }
 | 
|---|
| [551] | 172 |     error = MassMkdir(hwnd, szBuff);
 | 
|---|
 | 173 |     if (error)
 | 
|---|
| [2] | 174 |       Dos_Error(MB_ENTER,
 | 
|---|
| [551] | 175 |                 error,
 | 
|---|
 | 176 |                 hwnd,
 | 
|---|
 | 177 |                 __FILE__,
 | 
|---|
 | 178 |                 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
 | 
|---|
| [2] | 179 |     else {
 | 
|---|
| [551] | 180 |       if (copy && filename)
 | 
|---|
 | 181 |         strcpy(filename, szBuff);
 | 
|---|
| [2] | 182 |       return TRUE;
 | 
|---|
 | 183 |     }
 | 
|---|
 | 184 |   }
 | 
|---|
 | 185 |   return FALSE;
 | 
|---|
 | 186 | }
 | 
|---|
 | 187 | 
 | 
|---|
| [551] | 188 | void SetTargetDir(HWND hwnd, BOOL justshow)
 | 
|---|
 | 189 | {
 | 
|---|
| [2] | 190 | 
 | 
|---|
 | 191 |   char temp[CCHMAXPATH + 12];
 | 
|---|
 | 192 | 
 | 
|---|
| [551] | 193 |   if (!justshow) {
 | 
|---|
 | 194 |     strcpy(temp, targetdir);
 | 
|---|
 | 195 |     if (WinDlgBox(HWND_DESKTOP,
 | 
|---|
 | 196 |                   hwnd,
 | 
|---|
 | 197 |                   WalkTargetDlgProc,
 | 
|---|
 | 198 |                   FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
 | 
|---|
 | 199 |       strcpy(targetdir, temp);
 | 
|---|
 | 200 |       if (!fChangeTarget)
 | 
|---|
 | 201 |         PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
 | 
|---|
| [2] | 202 |     }
 | 
|---|
 | 203 |     else {
 | 
|---|
| [551] | 204 |       if (*targetdir &&
 | 
|---|
 | 205 |           saymsg(MB_YESNOCANCEL,
 | 
|---|
 | 206 |                  hwnd,
 | 
|---|
 | 207 |                  GetPString(IDS_CLEARTARGETTITLETEXT),
 | 
|---|
 | 208 |                  "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
 | 
|---|
 | 209 |         *targetdir = 0;
 | 
|---|
 | 210 |         PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
 | 
|---|
| [2] | 211 |       }
 | 
|---|
 | 212 |     }
 | 
|---|
 | 213 |   }
 | 
|---|
 | 214 | 
 | 
|---|
| [551] | 215 |   if (hwndBack) {
 | 
|---|
 | 216 |     if (fShowTarget)
 | 
|---|
| [2] | 217 |       sprintf(temp,
 | 
|---|
| [551] | 218 |               "%s%s%s%s",
 | 
|---|
 | 219 |               GetPString(IDS_TARGETDIRTITLETEXT),
 | 
|---|
 | 220 |               (*targetdir) ? "" : "<",
 | 
|---|
 | 221 |               (*targetdir) ?
 | 
|---|
 | 222 |               targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
 | 
|---|
| [2] | 223 |     else
 | 
|---|
 | 224 |       *temp = 0;
 | 
|---|
| [551] | 225 |     WinSetWindowText(hwndBack, temp);
 | 
|---|
| [2] | 226 |   }
 | 
|---|
 | 227 | }
 | 
|---|