source: trunk/dll/mkdir.c@ 1120

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

Replace save_dir2(dir) with strcpy(dir, pFM2SaveDirectory)

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