source: trunk/dll/mkdir.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • 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 1877 2015-10-11 21:43:27Z 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);
[1348]78 }
[551]79 else if (last == ERROR_ACCESS_DENIED) {
80 if (!IsFile(s))
81 last = 0;
[2]82 }
[551]83 if (was) {
[2]84 *p = '\\';
85 p++;
86 }
87 }
[551]88 while (p && *p);
[2]89 return last;
90}
91
[551]92APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
93{
[2]94
[1673]95 /**
[2]96 * bitmapped flags:
97 * 1 = don't ask to create if non-existent
98 */
99
[551]100 CHAR s[CCHMAXPATH], *p;
101 APIRET ret = 0, error;
102 INT isfile;
[1354]103 BOOL fResetVerify = FALSE;
[2]104
[551]105 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
106 strcpy(s, dir);
107 while ((p = strchr(s, '/')) != NULL)
[2]108 *p = '\\';
[551]109 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
[2]110 s[strlen(s) - 1] = 0;
[551]111 if (IsFullName(s)) {
112 if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
113 if (!(flags & 1))
114 saymsg(MB_CANCEL,
115 hwnd,
116 GetPString(IDS_NOPETEXT),
117 GetPString(IDS_DRIVEISTEXT),
118 toupper(*s),
119 ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
120 GetPString(IDS_BEINGIGNOREDTEXT) :
121 GetPString(IDS_INVALIDTEXT));
[2]122 return -5;
123 }
124 }
125 isfile = IsFile(s);
[551]126 if (isfile == -1) {
127 if (IsFullName(s)) {
128 if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
129 if (!(flags & 1))
130 saymsg(MB_CANCEL,
131 hwnd,
132 GetPString(IDS_NOPETEXT),
133 GetPString(IDS_DRIVEISTEXT),
134 toupper(*s), GetPString(IDS_NOWRITETEXT));
135 return -4;
[2]136 }
137 }
[551]138 if (!(flags & 1)) {
139 if (saymsg(MB_YESNO,
140 hwnd,
141 GetPString(IDS_CONFIRMTEXT),
142 GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
143 return -3;
[2]144 }
[1354]145 if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
146 DosSetVerify(FALSE);
147 fResetVerify = TRUE;
148 }
149 error = MassMkdir(hwnd, s);
150 if (fResetVerify) {
151 DosSetVerify(fVerify);
152 fResetVerify = FALSE;
153 }
[551]154 if (error) {
[2]155 Dos_Error(MB_CANCEL,
[551]156 error,
157 hwnd,
158 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
[2]159 ret = -1;
160 }
161 }
[551]162 else if (isfile) {
[2]163 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
[551]164 hwnd,
165 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
[2]166 ret = -2;
167 }
168 return ret;
169}
170
[551]171BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
172{
[2]173
174 STRINGINPARMS sip;
[551]175 CHAR szBuff[CCHMAXPATH];
176 APIRET error;
[1354]177 BOOL fResetVerify = FALSE;
[2]178
179Over:
180 sip.help = GetPString(IDS_MKDIRHELPTEXT);
181 sip.ret = szBuff;
[551]182 if (filename)
183 strcpy(szBuff, filename);
[2]184 else
[1104]185 strcpy(szBuff, pFM2SaveDirectory);
[2]186 MakeValidDir(szBuff);
[1438]187 AddBackslashToPath(szBuff);
188 //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
189 // strcat(szBuff, "\\");
[2]190 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
191 sip.inputlen = CCHMAXPATH - 1;
192 sip.title = GetPString(IDS_MKDIRTITLETEXT);
[551]193 if (WinDlgBox(HWND_DESKTOP,
194 hwnd,
195 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
196 if ((strchr(szBuff, '?') ||
197 strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
[2]198 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
[551]199 hwnd,
200 GetPString(IDS_ERRORTEXT),
201 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
[2]202 goto Over;
203 }
[1354]204 if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
205 DosSetVerify(FALSE);
206 fResetVerify = TRUE;
207 }
[551]208 error = MassMkdir(hwnd, szBuff);
[1354]209 if (fResetVerify) {
210 DosSetVerify(fVerify);
211 fResetVerify = FALSE;
212 }
[551]213 if (error)
[2]214 Dos_Error(MB_ENTER,
[551]215 error,
216 hwnd,
217 __FILE__,
218 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
[2]219 else {
[551]220 if (copy && filename)
221 strcpy(filename, szBuff);
[2]222 return TRUE;
223 }
224 }
225 return FALSE;
226}
227
[1675]228/*
229 * SetTargetDir sets or unsets the target directory
230 * either from the walk dialog or a directory dropped
231 * on the drivesback bar which is passed as "newtarget".
232 * justshow allows you to update the target without opening
233 * the walk dialog.
234 */
235void SetTargetDir(HWND hwnd, BOOL justshow, PSZ newtarget)
[551]236{
[2]237
238 char temp[CCHMAXPATH + 12];
239
[551]240 if (!justshow) {
241 strcpy(temp, targetdir);
242 if (WinDlgBox(HWND_DESKTOP,
243 hwnd,
244 WalkTargetDlgProc,
245 FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
246 strcpy(targetdir, temp);
247 if (!fChangeTarget)
248 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
[2]249 }
250 else {
[551]251 if (*targetdir &&
252 saymsg(MB_YESNOCANCEL,
253 hwnd,
254 GetPString(IDS_CLEARTARGETTITLETEXT),
[1402]255 GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
[551]256 *targetdir = 0;
257 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
[2]258 }
259 }
260 }
[1675]261 if (newtarget && justshow)
262 strcpy(targetdir, newtarget);
[551]263 if (hwndBack) {
264 if (fShowTarget)
[2]265 sprintf(temp,
[551]266 "%s%s%s%s",
267 GetPString(IDS_TARGETDIRTITLETEXT),
[1438]268 (*targetdir) ? NullStr : "<",
[551]269 (*targetdir) ?
[1438]270 targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
[2]271 else
272 *temp = 0;
[551]273 WinSetWindowText(hwndBack, temp);
[2]274 }
275}
[1316]276
277#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
Note: See TracBrowser for help on using the repository browser.