source: trunk/dll/mkdir.c@ 1225

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

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