source: trunk/dll/mkdir.c@ 1348

Last change on this file since 1348 was 1348, checked in by Gregg Young, 17 years ago

More code cleanup

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