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
RevLine 
[907]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
[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
[1358]14 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
[1438]15 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
[1545]16 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
[1675]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
[907]20
21***********************************************************************/
22
23#include <string.h>
24#include <ctype.h>
25
[2]26#define INCL_DOSERRORS
27#define INCL_WIN
[907]28#define INCL_LONGLONG // dircnrs.h
[2]29
[1187]30#include "fm3dll.h"
[1225]31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
32#include "mkdir.h"
[1210]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)
[2]37#include "fm3dlg.h"
38#include "fm3str.h"
[907]39#include "errutil.h" // Dos_Error...
40#include "strutil.h" // GetPString
[985]41#include "notebook.h" // targetdirectoy
[1163]42#include "walkem.h" // WalkTargetDlgProc
[1187]43#include "misc.h" // Broadcast
44#include "valid.h" // IsFullName
45#include "dirs.h" // save_dir2
46#include "input.h" // InputDlgProc
[1438]47#include "pathutil.h" // AddBackslashToPath
[2]48
[1210]49// Data definitions
50#pragma data_seg(GLOBAL2)
51CHAR targetdir[CCHMAXPATH];
52
[1354]53//static PSZ pszSrcFile = __FILE__;
[1348]54
[551]55APIRET MassMkdir(HWND hwndClient, CHAR * dir)
56{
57 APIRET last, was = 0;
58 CHAR *p;
59 CHAR s[CCHMAXPATH];
[2]60
[551]61 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
62 strcpy(s, dir);
[1545]63 ForwardslashToBackslash(s);
[2]64 p = s;
65 do {
[551]66 p = strchr(p, '\\');
67 if (p && p > s && *(p - 1) == ':')
68 p = strchr(p + 1, '\\');
69 if (p && *p) {
[2]70 *p = 0;
71 was = 1;
72 }
73 else
74 was = 0;
[551]75 last = DosCreateDir(s, NULL);
[1348]76 if (!last) {
[551]77 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
[1354]78 //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
[1348]79 }
[551]80 else if (last == ERROR_ACCESS_DENIED) {
81 if (!IsFile(s))
82 last = 0;
[2]83 }
[551]84 if (was) {
[2]85 *p = '\\';
86 p++;
87 }
88 }
[551]89 while (p && *p);
[2]90 return last;
91}
92
[551]93APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
94{
[2]95
[1673]96 /**
[2]97 * bitmapped flags:
98 * 1 = don't ask to create if non-existent
99 */
100
[551]101 CHAR s[CCHMAXPATH], *p;
102 APIRET ret = 0, error;
103 INT isfile;
[1354]104 BOOL fResetVerify = FALSE;
[2]105
[551]106 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
107 strcpy(s, dir);
108 while ((p = strchr(s, '/')) != NULL)
[2]109 *p = '\\';
[551]110 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
[2]111 s[strlen(s) - 1] = 0;
[551]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));
[2]123 return -5;
124 }
125 }
126 isfile = IsFile(s);
[551]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;
[2]137 }
138 }
[551]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;
[2]145 }
[1354]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 }
[551]155 if (error) {
[2]156 Dos_Error(MB_CANCEL,
[551]157 error,
158 hwnd,
159 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
[2]160 ret = -1;
161 }
162 }
[551]163 else if (isfile) {
[2]164 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
[551]165 hwnd,
166 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
[2]167 ret = -2;
168 }
169 return ret;
170}
171
[551]172BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
173{
[2]174
175 STRINGINPARMS sip;
[551]176 CHAR szBuff[CCHMAXPATH];
177 APIRET error;
[1354]178 BOOL fResetVerify = FALSE;
[2]179
180Over:
181 sip.help = GetPString(IDS_MKDIRHELPTEXT);
182 sip.ret = szBuff;
[551]183 if (filename)
184 strcpy(szBuff, filename);
[2]185 else
[1104]186 strcpy(szBuff, pFM2SaveDirectory);
[2]187 MakeValidDir(szBuff);
[1438]188 AddBackslashToPath(szBuff);
189 //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
190 // strcat(szBuff, "\\");
[2]191 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
192 sip.inputlen = CCHMAXPATH - 1;
193 sip.title = GetPString(IDS_MKDIRTITLETEXT);
[551]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)) {
[2]199 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
[551]200 hwnd,
201 GetPString(IDS_ERRORTEXT),
202 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
[2]203 goto Over;
204 }
[1354]205 if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
206 DosSetVerify(FALSE);
207 fResetVerify = TRUE;
208 }
[551]209 error = MassMkdir(hwnd, szBuff);
[1354]210 if (fResetVerify) {
211 DosSetVerify(fVerify);
212 fResetVerify = FALSE;
213 }
[551]214 if (error)
[2]215 Dos_Error(MB_ENTER,
[551]216 error,
217 hwnd,
218 __FILE__,
219 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
[2]220 else {
[551]221 if (copy && filename)
222 strcpy(filename, szBuff);
[2]223 return TRUE;
224 }
225 }
226 return FALSE;
227}
228
[1675]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)
[551]237{
[2]238
239 char temp[CCHMAXPATH + 12];
240
[551]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);
[2]250 }
251 else {
[551]252 if (*targetdir &&
253 saymsg(MB_YESNOCANCEL,
254 hwnd,
255 GetPString(IDS_CLEARTARGETTITLETEXT),
[1402]256 GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
[551]257 *targetdir = 0;
258 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
[2]259 }
260 }
261 }
[1675]262 if (newtarget && justshow)
263 strcpy(targetdir, newtarget);
[551]264 if (hwndBack) {
265 if (fShowTarget)
[2]266 sprintf(temp,
[551]267 "%s%s%s%s",
268 GetPString(IDS_TARGETDIRTITLETEXT),
[1438]269 (*targetdir) ? NullStr : "<",
[551]270 (*targetdir) ?
[1438]271 targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
[2]272 else
273 *temp = 0;
[551]274 WinSetWindowText(hwndBack, temp);
[2]275 }
276}
[1316]277
278#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
Note: See TracBrowser for help on using the repository browser.