source: trunk/dll/mkdir.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: mkdir.c 907 2008-01-06 07:26:17Z stevenhl $
5
6 Make directory dialog
7
8 Copyright (c) 1993-97 M. Kimes
9 Copyright (c) 2004, 2007 Steven H.Levine
10
11 01 Aug 04 SHL Baseline
12
13***********************************************************************/
14
15#include <string.h>
16#include <ctype.h>
17
18#define INCL_DOSERRORS
19#define INCL_WIN
20#define INCL_LONGLONG // dircnrs.h
21
22#include "fm3dlg.h"
23#include "fm3str.h"
24#include "errutil.h" // Dos_Error...
25#include "strutil.h" // GetPString
26#include "fm3dll.h"
27
28#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
29
30APIRET MassMkdir(HWND hwndClient, CHAR * dir)
31{
32 APIRET last, was = 0;
33 CHAR *p;
34 CHAR s[CCHMAXPATH];
35
36 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
37 strcpy(s, dir);
38 p = s;
39 while (*p) {
40 if (*p == '/')
41 *p = '\\';
42 p++;
43 }
44 p = s;
45 do {
46 p = strchr(p, '\\');
47 if (p && p > s && *(p - 1) == ':')
48 p = strchr(p + 1, '\\');
49 if (p && *p) {
50 *p = 0;
51 was = 1;
52 }
53 else
54 was = 0;
55 last = DosCreateDir(s, NULL);
56 if (!last)
57 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
58 else if (last == ERROR_ACCESS_DENIED) {
59 if (!IsFile(s))
60 last = 0;
61 }
62 if (was) {
63 *p = '\\';
64 p++;
65 }
66 }
67 while (p && *p);
68 return last;
69}
70
71APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
72{
73
74 /*
75 * bitmapped flags:
76 * 1 = don't ask to create if non-existent
77 */
78
79 CHAR s[CCHMAXPATH], *p;
80 APIRET ret = 0, error;
81 INT isfile;
82
83 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
84 strcpy(s, dir);
85 while ((p = strchr(s, '/')) != NULL)
86 *p = '\\';
87 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
88 s[strlen(s) - 1] = 0;
89 if (IsFullName(s)) {
90 if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
91 if (!(flags & 1))
92 saymsg(MB_CANCEL,
93 hwnd,
94 GetPString(IDS_NOPETEXT),
95 GetPString(IDS_DRIVEISTEXT),
96 toupper(*s),
97 ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
98 GetPString(IDS_BEINGIGNOREDTEXT) :
99 GetPString(IDS_INVALIDTEXT));
100 return -5;
101 }
102 }
103 isfile = IsFile(s);
104 if (isfile == -1) {
105 if (IsFullName(s)) {
106 if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
107 if (!(flags & 1))
108 saymsg(MB_CANCEL,
109 hwnd,
110 GetPString(IDS_NOPETEXT),
111 GetPString(IDS_DRIVEISTEXT),
112 toupper(*s), GetPString(IDS_NOWRITETEXT));
113 return -4;
114 }
115 }
116 if (!(flags & 1)) {
117 if (saymsg(MB_YESNO,
118 hwnd,
119 GetPString(IDS_CONFIRMTEXT),
120 GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
121 return -3;
122 }
123 error = MassMkdir(hwndClient, s);
124 if (error) {
125 Dos_Error(MB_CANCEL,
126 error,
127 hwnd,
128 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
129 ret = -1;
130 }
131 }
132 else if (isfile) {
133 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
134 hwnd,
135 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
136 ret = -2;
137 }
138 return ret;
139}
140
141BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
142{
143
144 STRINGINPARMS sip;
145 CHAR szBuff[CCHMAXPATH];
146 APIRET error;
147
148Over:
149 sip.help = GetPString(IDS_MKDIRHELPTEXT);
150 sip.ret = szBuff;
151 if (filename)
152 strcpy(szBuff, filename);
153 else
154 save_dir2(szBuff);
155 MakeValidDir(szBuff);
156 if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
157 strcat(szBuff, "\\");
158 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
159 sip.inputlen = CCHMAXPATH - 1;
160 sip.title = GetPString(IDS_MKDIRTITLETEXT);
161 if (WinDlgBox(HWND_DESKTOP,
162 hwnd,
163 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
164 if ((strchr(szBuff, '?') ||
165 strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
166 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
167 hwnd,
168 GetPString(IDS_ERRORTEXT),
169 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
170 goto Over;
171 }
172 error = MassMkdir(hwnd, szBuff);
173 if (error)
174 Dos_Error(MB_ENTER,
175 error,
176 hwnd,
177 __FILE__,
178 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
179 else {
180 if (copy && filename)
181 strcpy(filename, szBuff);
182 return TRUE;
183 }
184 }
185 return FALSE;
186}
187
188void SetTargetDir(HWND hwnd, BOOL justshow)
189{
190
191 char temp[CCHMAXPATH + 12];
192
193 if (!justshow) {
194 strcpy(temp, targetdir);
195 if (WinDlgBox(HWND_DESKTOP,
196 hwnd,
197 WalkTargetDlgProc,
198 FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
199 strcpy(targetdir, temp);
200 if (!fChangeTarget)
201 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
202 }
203 else {
204 if (*targetdir &&
205 saymsg(MB_YESNOCANCEL,
206 hwnd,
207 GetPString(IDS_CLEARTARGETTITLETEXT),
208 "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
209 *targetdir = 0;
210 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
211 }
212 }
213 }
214
215 if (hwndBack) {
216 if (fShowTarget)
217 sprintf(temp,
218 "%s%s%s%s",
219 GetPString(IDS_TARGETDIRTITLETEXT),
220 (*targetdir) ? "" : "<",
221 (*targetdir) ?
222 targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
223 else
224 *temp = 0;
225 WinSetWindowText(hwndBack, temp);
226 }
227}
Note: See TracBrowser for help on using the repository browser.