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