source: trunk/dll/mkdir.c@ 1354

Last change on this file since 1354 was 1354, checked in by Gregg Young, 17 years ago

Added driveflags to over ride write verify for USB removable drives that fail when it is on (Ticket 323); A flag to prevent directory name from being broadcast to drives in the tree cnr prior to a recursive scan of the drive (causes dbl directory names Ticket 321) Add option for multithreaded recursive scan of user selected drives at startup (Ticket 322).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
RevLine 
[907]1
2/***********************************************************************
3
4 $Id: mkdir.c 1354 2008-12-25 22:43:34Z 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
[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)
44CHAR targetdir[CCHMAXPATH];
45
[1354]46//static PSZ pszSrcFile = __FILE__;
[1348]47
[551]48APIRET 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);
[1348]74 if (!last) {
[551]75 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
[1354]76 //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
[1348]77 }
[551]78 else if (last == ERROR_ACCESS_DENIED) {
79 if (!IsFile(s))
80 last = 0;
[2]81 }
[551]82 if (was) {
[2]83 *p = '\\';
84 p++;
85 }
86 }
[551]87 while (p && *p);
[2]88 return last;
89}
90
[551]91APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
92{
[2]93
94 /*
95 * bitmapped flags:
96 * 1 = don't ask to create if non-existent
97 */
98
[551]99 CHAR s[CCHMAXPATH], *p;
100 APIRET ret = 0, error;
101 INT isfile;
[1354]102 BOOL fResetVerify = FALSE;
[2]103
[551]104 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
105 strcpy(s, dir);
106 while ((p = strchr(s, '/')) != NULL)
[2]107 *p = '\\';
[551]108 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
[2]109 s[strlen(s) - 1] = 0;
[551]110 if (IsFullName(s)) {
111 if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
112 if (!(flags & 1))
113 saymsg(MB_CANCEL,
114 hwnd,
115 GetPString(IDS_NOPETEXT),
116 GetPString(IDS_DRIVEISTEXT),
117 toupper(*s),
118 ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
119 GetPString(IDS_BEINGIGNOREDTEXT) :
120 GetPString(IDS_INVALIDTEXT));
[2]121 return -5;
122 }
123 }
124 isfile = IsFile(s);
[551]125 if (isfile == -1) {
126 if (IsFullName(s)) {
127 if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
128 if (!(flags & 1))
129 saymsg(MB_CANCEL,
130 hwnd,
131 GetPString(IDS_NOPETEXT),
132 GetPString(IDS_DRIVEISTEXT),
133 toupper(*s), GetPString(IDS_NOWRITETEXT));
134 return -4;
[2]135 }
136 }
[551]137 if (!(flags & 1)) {
138 if (saymsg(MB_YESNO,
139 hwnd,
140 GetPString(IDS_CONFIRMTEXT),
141 GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
142 return -3;
[2]143 }
[1354]144 if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
145 DosSetVerify(FALSE);
146 fResetVerify = TRUE;
147 }
148 error = MassMkdir(hwnd, s);
149 if (fResetVerify) {
150 DosSetVerify(fVerify);
151 fResetVerify = FALSE;
152 }
[551]153 if (error) {
[2]154 Dos_Error(MB_CANCEL,
[551]155 error,
156 hwnd,
157 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
[2]158 ret = -1;
159 }
160 }
[551]161 else if (isfile) {
[2]162 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
[551]163 hwnd,
164 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
[2]165 ret = -2;
166 }
167 return ret;
168}
169
[551]170BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
171{
[2]172
173 STRINGINPARMS sip;
[551]174 CHAR szBuff[CCHMAXPATH];
175 APIRET error;
[1354]176 BOOL fResetVerify = FALSE;
[2]177
178Over:
179 sip.help = GetPString(IDS_MKDIRHELPTEXT);
180 sip.ret = szBuff;
[551]181 if (filename)
182 strcpy(szBuff, filename);
[2]183 else
[1104]184 strcpy(szBuff, pFM2SaveDirectory);
[2]185 MakeValidDir(szBuff);
[551]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]226void 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),
246 "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
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),
258 (*targetdir) ? "" : "<",
259 (*targetdir) ?
260 targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
[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)
Note: See TracBrowser for help on using the repository browser.