source: trunk/dll/mkdir.c@ 1194

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

Ticket 187: Draft 2: Move remaining function declarations

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