source: trunk/dll/mkdir.c@ 1330

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

Code clean up -- remove redundant code; move code to match openwatcom requirements etc.

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