source: trunk/dll/mkdir.c@ 1178

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