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