source: trunk/dll/mkdir.c@ 1163

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

Ticket 187: Draft 1: Functions only

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