source: trunk/dll/mkdir.c@ 1844

Last change on this file since 1844 was 1675, checked in by Gregg Young, 13 years ago

Enhance traget directory drop to give the option of changing the directory or carrying out an operation to the current target; Added an error message for target=None; Added parameter to SetTargetDir. Ticket 373

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: mkdir.c 1675 2012-12-30 23:15:44Z 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 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
16 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
17 30 Dec 12 GKY Enhance traget directory drop to give the option of changing the directory or carrying out an
18 operation to the current target; Added an error message for target=None;
19 Added parameter to SetTargetDir
20
21***********************************************************************/
22
23#include <string.h>
24#include <ctype.h>
25
26#define INCL_DOSERRORS
27#define INCL_WIN
28#define INCL_LONGLONG // dircnrs.h
29
30#include "fm3dll.h"
31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
32#include "mkdir.h"
33#include "common.h" // Data declaration(s)
34#include "init.h" // Data declaration(s)
35#include "info.h" // Data declaration(s)
36#include "mainwnd.h" // Data declaration(s)
37#include "fm3dlg.h"
38#include "fm3str.h"
39#include "errutil.h" // Dos_Error...
40#include "strutil.h" // GetPString
41#include "notebook.h" // targetdirectoy
42#include "walkem.h" // WalkTargetDlgProc
43#include "misc.h" // Broadcast
44#include "valid.h" // IsFullName
45#include "dirs.h" // save_dir2
46#include "input.h" // InputDlgProc
47#include "pathutil.h" // AddBackslashToPath
48
49// Data definitions
50#pragma data_seg(GLOBAL2)
51CHAR targetdir[CCHMAXPATH];
52
53//static PSZ pszSrcFile = __FILE__;
54
55APIRET MassMkdir(HWND hwndClient, CHAR * dir)
56{
57 APIRET last, was = 0;
58 CHAR *p;
59 CHAR s[CCHMAXPATH];
60
61 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
62 strcpy(s, dir);
63 ForwardslashToBackslash(s);
64 p = s;
65 do {
66 p = strchr(p, '\\');
67 if (p && p > s && *(p - 1) == ':')
68 p = strchr(p + 1, '\\');
69 if (p && *p) {
70 *p = 0;
71 was = 1;
72 }
73 else
74 was = 0;
75 last = DosCreateDir(s, NULL);
76 if (!last) {
77 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
78 //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
79 }
80 else if (last == ERROR_ACCESS_DENIED) {
81 if (!IsFile(s))
82 last = 0;
83 }
84 if (was) {
85 *p = '\\';
86 p++;
87 }
88 }
89 while (p && *p);
90 return last;
91}
92
93APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
94{
95
96 /**
97 * bitmapped flags:
98 * 1 = don't ask to create if non-existent
99 */
100
101 CHAR s[CCHMAXPATH], *p;
102 APIRET ret = 0, error;
103 INT isfile;
104 BOOL fResetVerify = FALSE;
105
106 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
107 strcpy(s, dir);
108 while ((p = strchr(s, '/')) != NULL)
109 *p = '\\';
110 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
111 s[strlen(s) - 1] = 0;
112 if (IsFullName(s)) {
113 if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
114 if (!(flags & 1))
115 saymsg(MB_CANCEL,
116 hwnd,
117 GetPString(IDS_NOPETEXT),
118 GetPString(IDS_DRIVEISTEXT),
119 toupper(*s),
120 ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
121 GetPString(IDS_BEINGIGNOREDTEXT) :
122 GetPString(IDS_INVALIDTEXT));
123 return -5;
124 }
125 }
126 isfile = IsFile(s);
127 if (isfile == -1) {
128 if (IsFullName(s)) {
129 if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
130 if (!(flags & 1))
131 saymsg(MB_CANCEL,
132 hwnd,
133 GetPString(IDS_NOPETEXT),
134 GetPString(IDS_DRIVEISTEXT),
135 toupper(*s), GetPString(IDS_NOWRITETEXT));
136 return -4;
137 }
138 }
139 if (!(flags & 1)) {
140 if (saymsg(MB_YESNO,
141 hwnd,
142 GetPString(IDS_CONFIRMTEXT),
143 GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
144 return -3;
145 }
146 if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
147 DosSetVerify(FALSE);
148 fResetVerify = TRUE;
149 }
150 error = MassMkdir(hwnd, s);
151 if (fResetVerify) {
152 DosSetVerify(fVerify);
153 fResetVerify = FALSE;
154 }
155 if (error) {
156 Dos_Error(MB_CANCEL,
157 error,
158 hwnd,
159 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
160 ret = -1;
161 }
162 }
163 else if (isfile) {
164 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
165 hwnd,
166 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
167 ret = -2;
168 }
169 return ret;
170}
171
172BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
173{
174
175 STRINGINPARMS sip;
176 CHAR szBuff[CCHMAXPATH];
177 APIRET error;
178 BOOL fResetVerify = FALSE;
179
180Over:
181 sip.help = GetPString(IDS_MKDIRHELPTEXT);
182 sip.ret = szBuff;
183 if (filename)
184 strcpy(szBuff, filename);
185 else
186 strcpy(szBuff, pFM2SaveDirectory);
187 MakeValidDir(szBuff);
188 AddBackslashToPath(szBuff);
189 //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
190 // strcat(szBuff, "\\");
191 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
192 sip.inputlen = CCHMAXPATH - 1;
193 sip.title = GetPString(IDS_MKDIRTITLETEXT);
194 if (WinDlgBox(HWND_DESKTOP,
195 hwnd,
196 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
197 if ((strchr(szBuff, '?') ||
198 strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
199 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
200 hwnd,
201 GetPString(IDS_ERRORTEXT),
202 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
203 goto Over;
204 }
205 if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
206 DosSetVerify(FALSE);
207 fResetVerify = TRUE;
208 }
209 error = MassMkdir(hwnd, szBuff);
210 if (fResetVerify) {
211 DosSetVerify(fVerify);
212 fResetVerify = FALSE;
213 }
214 if (error)
215 Dos_Error(MB_ENTER,
216 error,
217 hwnd,
218 __FILE__,
219 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
220 else {
221 if (copy && filename)
222 strcpy(filename, szBuff);
223 return TRUE;
224 }
225 }
226 return FALSE;
227}
228
229/*
230 * SetTargetDir sets or unsets the target directory
231 * either from the walk dialog or a directory dropped
232 * on the drivesback bar which is passed as "newtarget".
233 * justshow allows you to update the target without opening
234 * the walk dialog.
235 */
236void SetTargetDir(HWND hwnd, BOOL justshow, PSZ newtarget)
237{
238
239 char temp[CCHMAXPATH + 12];
240
241 if (!justshow) {
242 strcpy(temp, targetdir);
243 if (WinDlgBox(HWND_DESKTOP,
244 hwnd,
245 WalkTargetDlgProc,
246 FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
247 strcpy(targetdir, temp);
248 if (!fChangeTarget)
249 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
250 }
251 else {
252 if (*targetdir &&
253 saymsg(MB_YESNOCANCEL,
254 hwnd,
255 GetPString(IDS_CLEARTARGETTITLETEXT),
256 GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
257 *targetdir = 0;
258 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
259 }
260 }
261 }
262 if (newtarget && justshow)
263 strcpy(targetdir, newtarget);
264 if (hwndBack) {
265 if (fShowTarget)
266 sprintf(temp,
267 "%s%s%s%s",
268 GetPString(IDS_TARGETDIRTITLETEXT),
269 (*targetdir) ? NullStr : "<",
270 (*targetdir) ?
271 targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
272 else
273 *temp = 0;
274 WinSetWindowText(hwndBack, temp);
275 }
276}
277
278#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
Note: See TracBrowser for help on using the repository browser.