source: trunk/dll/mkdir.c@ 1330

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

Code clean up -- remove redundant code; move code to match openwatcom requirements etc.

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