source: trunk/dll/mkdir.c@ 1211

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

Ticket 187: Move data declarations/definitions out of fm3dll.h

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