source: trunk/dll/mkdir.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
RevLine 
[907]1
2/***********************************************************************
3
4 $Id: mkdir.c 1402 2009-03-14 17:17:59Z 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
[907]15
16***********************************************************************/
17
18#include <string.h>
19#include <ctype.h>
20
[2]21#define INCL_DOSERRORS
22#define INCL_WIN
[907]23#define INCL_LONGLONG // dircnrs.h
[2]24
[1187]25#include "fm3dll.h"
[1225]26#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
27#include "mkdir.h"
[1210]28#include "common.h" // Data declaration(s)
29#include "init.h" // Data declaration(s)
30#include "info.h" // Data declaration(s)
31#include "mainwnd.h" // Data declaration(s)
[2]32#include "fm3dlg.h"
33#include "fm3str.h"
[907]34#include "errutil.h" // Dos_Error...
35#include "strutil.h" // GetPString
[985]36#include "notebook.h" // targetdirectoy
[1163]37#include "walkem.h" // WalkTargetDlgProc
[1187]38#include "misc.h" // Broadcast
39#include "valid.h" // IsFullName
40#include "dirs.h" // save_dir2
41#include "input.h" // InputDlgProc
[2]42
[1210]43// Data definitions
44#pragma data_seg(GLOBAL2)
45CHAR targetdir[CCHMAXPATH];
46
[1354]47//static PSZ pszSrcFile = __FILE__;
[1348]48
[551]49APIRET MassMkdir(HWND hwndClient, CHAR * dir)
50{
51 APIRET last, was = 0;
52 CHAR *p;
53 CHAR s[CCHMAXPATH];
[2]54
[551]55 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
56 strcpy(s, dir);
[2]57 p = s;
[551]58 while (*p) {
59 if (*p == '/')
[2]60 *p = '\\';
61 p++;
62 }
63 p = s;
64 do {
[551]65 p = strchr(p, '\\');
66 if (p && p > s && *(p - 1) == ':')
67 p = strchr(p + 1, '\\');
68 if (p && *p) {
[2]69 *p = 0;
70 was = 1;
71 }
72 else
73 was = 0;
[551]74 last = DosCreateDir(s, NULL);
[1348]75 if (!last) {
[551]76 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
[1354]77 //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
[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
95 /*
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);
[551]187 if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
188 strcat(szBuff, "\\");
[2]189 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
190 sip.inputlen = CCHMAXPATH - 1;
191 sip.title = GetPString(IDS_MKDIRTITLETEXT);
[551]192 if (WinDlgBox(HWND_DESKTOP,
193 hwnd,
194 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
195 if ((strchr(szBuff, '?') ||
196 strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
[2]197 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
[551]198 hwnd,
199 GetPString(IDS_ERRORTEXT),
200 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
[2]201 goto Over;
202 }
[1354]203 if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
204 DosSetVerify(FALSE);
205 fResetVerify = TRUE;
206 }
[551]207 error = MassMkdir(hwnd, szBuff);
[1354]208 if (fResetVerify) {
209 DosSetVerify(fVerify);
210 fResetVerify = FALSE;
211 }
[551]212 if (error)
[2]213 Dos_Error(MB_ENTER,
[551]214 error,
215 hwnd,
216 __FILE__,
217 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
[2]218 else {
[551]219 if (copy && filename)
220 strcpy(filename, szBuff);
[2]221 return TRUE;
222 }
223 }
224 return FALSE;
225}
226
[551]227void SetTargetDir(HWND hwnd, BOOL justshow)
228{
[2]229
230 char temp[CCHMAXPATH + 12];
231
[551]232 if (!justshow) {
233 strcpy(temp, targetdir);
234 if (WinDlgBox(HWND_DESKTOP,
235 hwnd,
236 WalkTargetDlgProc,
237 FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
238 strcpy(targetdir, temp);
239 if (!fChangeTarget)
240 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
[2]241 }
242 else {
[551]243 if (*targetdir &&
244 saymsg(MB_YESNOCANCEL,
245 hwnd,
246 GetPString(IDS_CLEARTARGETTITLETEXT),
[1402]247 GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
[551]248 *targetdir = 0;
249 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
[2]250 }
251 }
252 }
253
[551]254 if (hwndBack) {
255 if (fShowTarget)
[2]256 sprintf(temp,
[551]257 "%s%s%s%s",
258 GetPString(IDS_TARGETDIRTITLETEXT),
259 (*targetdir) ? "" : "<",
260 (*targetdir) ?
261 targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
[2]262 else
263 *temp = 0;
[551]264 WinSetWindowText(hwndBack, temp);
[2]265 }
266}
[1316]267
268#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
Note: See TracBrowser for help on using the repository browser.