source: trunk/dll/mkdir.c@ 1120

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

Replace save_dir2(dir) with strcpy(dir, pFM2SaveDirectory)

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