source: trunk/dll/mkdir.c@ 1348

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

More code cleanup

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