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
RevLine 
[907]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
[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"
[2]25#include "fm3dlg.h"
26#include "fm3str.h"
[907]27#include "errutil.h" // Dos_Error...
28#include "strutil.h" // GetPString
[985]29#include "notebook.h" // targetdirectoy
[1163]30#include "mkdir.h"
31#include "walkem.h" // WalkTargetDlgProc
[1187]32#include "misc.h" // Broadcast
33#include "valid.h" // IsFullName
34#include "dirs.h" // save_dir2
35#include "input.h" // InputDlgProc
[2]36
37#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
38
[551]39APIRET MassMkdir(HWND hwndClient, CHAR * dir)
40{
41 APIRET last, was = 0;
42 CHAR *p;
43 CHAR s[CCHMAXPATH];
[2]44
[551]45 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
46 strcpy(s, dir);
[2]47 p = s;
[551]48 while (*p) {
49 if (*p == '/')
[2]50 *p = '\\';
51 p++;
52 }
53 p = s;
54 do {
[551]55 p = strchr(p, '\\');
56 if (p && p > s && *(p - 1) == ':')
57 p = strchr(p + 1, '\\');
58 if (p && *p) {
[2]59 *p = 0;
60 was = 1;
61 }
62 else
63 was = 0;
[551]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;
[2]70 }
[551]71 if (was) {
[2]72 *p = '\\';
73 p++;
74 }
75 }
[551]76 while (p && *p);
[2]77 return last;
78}
79
[551]80APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
81{
[2]82
83 /*
84 * bitmapped flags:
85 * 1 = don't ask to create if non-existent
86 */
87
[551]88 CHAR s[CCHMAXPATH], *p;
89 APIRET ret = 0, error;
90 INT isfile;
[2]91
[551]92 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
93 strcpy(s, dir);
94 while ((p = strchr(s, '/')) != NULL)
[2]95 *p = '\\';
[551]96 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
[2]97 s[strlen(s) - 1] = 0;
[551]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));
[2]109 return -5;
110 }
111 }
112 isfile = IsFile(s);
[551]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;
[2]123 }
124 }
[551]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;
[2]131 }
[551]132 error = MassMkdir(hwndClient, s);
133 if (error) {
[2]134 Dos_Error(MB_CANCEL,
[551]135 error,
136 hwnd,
137 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
[2]138 ret = -1;
139 }
140 }
[551]141 else if (isfile) {
[2]142 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
[551]143 hwnd,
144 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
[2]145 ret = -2;
146 }
147 return ret;
148}
149
[551]150BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
151{
[2]152
153 STRINGINPARMS sip;
[551]154 CHAR szBuff[CCHMAXPATH];
155 APIRET error;
[2]156
157Over:
158 sip.help = GetPString(IDS_MKDIRHELPTEXT);
159 sip.ret = szBuff;
[551]160 if (filename)
161 strcpy(szBuff, filename);
[2]162 else
[1104]163 strcpy(szBuff, pFM2SaveDirectory);
[2]164 MakeValidDir(szBuff);
[551]165 if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
166 strcat(szBuff, "\\");
[2]167 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
168 sip.inputlen = CCHMAXPATH - 1;
169 sip.title = GetPString(IDS_MKDIRTITLETEXT);
[551]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)) {
[2]175 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
[551]176 hwnd,
177 GetPString(IDS_ERRORTEXT),
178 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
[2]179 goto Over;
180 }
[551]181 error = MassMkdir(hwnd, szBuff);
182 if (error)
[2]183 Dos_Error(MB_ENTER,
[551]184 error,
185 hwnd,
186 __FILE__,
187 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
[2]188 else {
[551]189 if (copy && filename)
190 strcpy(filename, szBuff);
[2]191 return TRUE;
192 }
193 }
194 return FALSE;
195}
196
[551]197void SetTargetDir(HWND hwnd, BOOL justshow)
198{
[2]199
200 char temp[CCHMAXPATH + 12];
201
[551]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);
[2]211 }
212 else {
[551]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);
[2]220 }
221 }
222 }
223
[551]224 if (hwndBack) {
225 if (fShowTarget)
[2]226 sprintf(temp,
[551]227 "%s%s%s%s",
228 GetPString(IDS_TARGETDIRTITLETEXT),
229 (*targetdir) ? "" : "<",
230 (*targetdir) ?
231 targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
[2]232 else
233 *temp = 0;
[551]234 WinSetWindowText(hwndBack, temp);
[2]235 }
236}
Note: See TracBrowser for help on using the repository browser.