source: trunk/dll/mkdir.c@ 1210

Last change on this file since 1210 was 1210, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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