17#define WIN95_LONGFILENAME_MAX 260
19 static tchar serverNamePrefix[] =
_T(
"\\\\");
22 static tchar ldevTerminatorCh =
_T(
':');
23 static tchar ldevTerminatorStr[] =
_T(
":");
25 static tchar dirSeparator[] =
_T(
"/");
27 static tchar dirSeparatorStr[] =
_T(
"/");
29 static tchar dirSeparator[] =
_T(
"\\/");
31 static tchar dirSeparatorStr[] =
_T(
"\\");
33 static tchar extSeparatorCh =
_T(
'.');
34 static tchar extSeparatorStr[] =
_T(
".");
51static const tchar* fn_find(
const tchar* start,
const tchar* end,
int match)
53 while (start != end && *start != match)
61 while (start != end && fn_find(set, setend, *start) == setend)
66static const tchar* fn_findl(
const tchar* start,
const tchar* end,
int match)
68 while (start != end && *start != match)
76 while (start != end && fn_find(set, setend, *start) == setend)
84 while (start != end && *skip && *start == *skip)
116 const tchar* serverNameEnd = fn_strend(serverName);
121 const tchar* ds = fn_find(serverName, serverNameEnd, dirSeparator);
122 return tstring(serverName, 0,
static_cast<int>(ds - serverName));
129tstring __formDevice(
const tchar* deviceName,
bool isUNC)
134 const tchar* deviceNameEnd = fn_strend(deviceName);
138 deviceNameEnd = fn_find(deviceName, deviceNameEnd, dirSeparator);
140 deviceNameEnd = fn_find(deviceName, deviceNameEnd, ldevTerminatorCh);
142 return tstring(deviceName, 0,
static_cast<int>(deviceNameEnd - deviceName));
155 const tchar* pathEnd = fn_strend(path);
159 const tchar* dvs = fn_find(path, pathEnd, ldevTerminatorCh);
164 return tstring(path, 0,
static_cast<int>(pathEnd - path));
182 const tchar* fileEnd = fn_strend(file);
184 const tchar* ds = fn_findl(fileEnd-1, file-1, dirSeparator);
188 const tchar* es = fn_findl(fileEnd-1, file-1, extSeparatorCh);
192 return tstring(file, 0,
static_cast<int>(fileEnd - file));
209 const tchar* extEnd = fn_strend(ext);
211 const tchar* ds = fn_findl(extEnd-1, ext-1, dirSeparator);
215 const tchar* es = fn_findl(extEnd-1, ext-1, extSeparatorCh);
219 return tstring(extSeparatorStr) + ext;
265 LPCTSTR file, LPCTSTR ext)
269 Unc = serverName !=
nullptr;
286 const tchar* freeformEnd = fn_strend(freeform);
288 if (*freeform ==
'\0')
302 nextp = fn_skipstr(freeform, freeformEnd, serverNamePrefix);
306 nextp = fn_find(freeform, freeformEnd, dirSeparator);
308 freeform = nextp + 1;
310 nextp = fn_find(freeform, freeformEnd, dirSeparator);
312 freeform = nextp + 1;
318 nextp = fn_find(freeform, freeformEnd, ldevTerminatorCh);
319 if (nextp != freeformEnd) {
321 freeform = nextp + 1;
330 nextp = fn_findl(freeformEnd-1, freeform-1, extSeparatorCh);
333 const tchar* dirp = fn_findl(freeformEnd-1, freeform-1, dirSeparator);
336 ExtStr =
tstring(nextp, 0,
static_cast<int>(freeformEnd-nextp));
342 FileStr =
tstring(dirp+1, 0,
static_cast<int>(freeformEnd - (dirp+1)));
352 if (freeformEnd > freeform)
353 PathStr =
tstring(freeform, 0,
static_cast<int>(freeformEnd-freeform));
364 Parse(freeform,pathOnly);
373 Parse(freeform.c_str(),pathOnly);
388 int tmpLen = ::GetTempPath(0,
nullptr);
390 tchar* tmpPath = __clnObj;
391 ::GetTempPath(tmpLen, tmpPath);
398 ::GetTempFileName(
static_cast<tchar*
>(tmpPath),
_T(
"TFN"), 0, tmpFile);
418 LPCTSTR path = _tgetenv(
_T(
"wonbootdir"));
438 ::GetComputerName(tmp, &size);
567 if (GetFileTitle(canonical.c_str(), tmp,
COUNTOF(tmp)) == 0)
597 const tchar* addPath =
_T(
"\\...");
601 const auto pos = subpath.find_last_of(dirSeparatorStr);
602 if (pos == subpath.npos || len <= 5)
608 tstring lastpath = subpath.substr(pos);
612 int length =
static_cast<int>(len - 4 - lastpath.length());
613 while(length < 0 && lastpath.length() > 0){
614 lastpath = lastpath.substr(1);
615 length =
static_cast<int>(len - 4 - lastpath.length());
620 while(
static_cast<int>(subpath.length()) > length && subpath.length() > 0){
621 const auto pos = subpath.find_last_of(dirSeparatorStr);
622 if (pos != subpath.npos)
636 else if(s.length() > len){
652 tstring attempt = This.GetParts(parts[index]);
653 if(!attempt.empty()){
654 tchar lastCh = attempt.c_str()[attempt.length()-1];
655 if(lastCh !=
_T(
'\\') && lastCh !=
_T(
'/'))
656 attempt += dirSeparatorStr;
687 const uint n =
static_cast<uint>(maxLen);
689 tstring attempt = getAttempt(*
this, fname, 0);
696 if (n < attempt.length())
698 const tstring dname = getAttempt(*
this, fname, 1);
699 if (n > dname.length() + 3)
702 trimPath(p, n -
static_cast<int>(dname.length()));
703 if (p.length() > 0 && p[p.length() - 1] != dirSeparatorStr[0])
704 p += dirSeparatorStr;
709 attempt = keepName ? fname : trimmStr(fname, n);
726 ofs.cBytes =
sizeof ofs;
739 ofs.cBytes =
sizeof ofs;
741 return ::OpenFile(
_W2A(
Canonical().c_str()), &ofs, OF_EXIST) != -1;
745 WIN32_FIND_DATA data;
749 return (h != INVALID_HANDLE_VALUE);
822 has |= (
ExtStr.length() > 0);
964 if (
_tcschr(dirSeparator, subdir[0]) ==
nullptr)
982struct __TFindFileStr{
984 WIN32_FIND_DATA Data;
994void __FillFileStr( __TFindFileStr& data, TFileStatus& status);
998void __FillFileStr( __TFindFileStr& data, TFileStatus& status)
1000 ::_tcscpy(status.fullName, data.Data.cFileName);
1001 status.attribute =
__sys2Atr(data.Data.dwFileAttributes);
1004 status.accessTime =
TTime(
TFileTime(data.Data.ftLastAccessTime));
1005 status.size = data.Data.nFileSizeLow;
1015 __TFindFileStr findData;
1016 findData.Handle = ::FindFirstFile(fileName.c_str(), &findData.Data);
1017 if(findData.Handle == INVALID_HANDLE_VALUE)
1020 __FillFileStr(findData, status);
1024 ::FindClose(findData.Handle);
1049 if(!::SetFileTime(handle->
Handle, &ftCreation, &ftLastAccess, &ftLastWrite))
1053 if(!::SetFileAttributes(fileName.c_str(), attr))
1056 WARN(1,
"TFile::SetStatus() error ::SetFileAttributes(), line: " << __LINE__);
1076 __TFindFileStr* data =
new __TFindFileStr;
1082 data->Direct =
tstring(wildName.c_str()) +
_T(
"\\");
1086 data->Handle = ::FindFirstFile(wildName.c_str(), &data->Data);
1087 if(data->Handle != INVALID_HANDLE_VALUE){
1088 __FillFileStr( *data,
Status);
1097 if (
Data && (
static_cast<__TFindFileStr*
>(
Data))->Handle != INVALID_HANDLE_VALUE)
1098 ::FindClose((
static_cast<__TFindFileStr*
>(
Data))->Handle);
1100 delete static_cast<__TFindFileStr*
>(
Data);
1107 __TFindFileStr& data = *
static_cast<__TFindFileStr*
>(findData);
1108 if (!::FindNextFile(data.Handle, &data.Data))
1111 __FillFileStr(data, status);
#define WARN(condition, message)
The TFile class encapsulates standard file characteristics and operations.
bool IsOpen() const
Returns true if the file is open, false otherwise.
@ OpenExisting
Opens the file. The function fails if the file does not exist.
virtual bool Length(uint64 newLen)
Resizes file to newLen.
virtual TFileHandle * GetHandle() const
Returns Handle.
The TFileName class constructs filenames.
bool Exists() const
Determines whether the device, directory, or file exists.
TFileName()
Constructs an empty filename.
const tchar * Title() const
The Title member function uses system conventions to get a human-readable rendering of the filename a...
const tchar * CanonicalStr(bool forceUNC=false) const
tstring DeviceStr
Holds the device filename part.
TFileName & StripParts(uint p)
Removes the specified filename parts from this set of parts.
tchar NameBuffer[_MAX_PATH]
tchar * GetFullFileNameNoExt()
TFileName & MergeParts(uint p, const TFileName &source)
Replaces the specified parts in this with the parts from source.
@ Device
Logical device or sharename.
@ Path
Directory path to the file.
@ File
Filename part without the extension.
tchar * GetNameAndExt() const
tstring ServerStr
Holds the server filename part.
const tstring & Canonical(bool forceUNC=false) const
Return normal fully qualified path string.
void Parse(LPCTSTR freeform, bool pathOnly=false)
Parses the freeform string into the filename parts.
int CreateDir() const
Creates the directory associated with this filename.
TFileName & SetPart(uint p, const tstring &partStr)
Replaces the specified filename parts with parts extracted from partStr.
int GetStatus(TFileStatus &status) const
Get the file status struct for the item associated with this filename.
int ChangeDir() const
Changes the current directory to the directory associated with this filename.
tstring ExtStr
Holds the extension filename part.
const tchar * Squeezed(int maxLen, bool keepName=true) const
Obtains a human-readable form of the filename.
bool Unc
true if UNC naming convention in use; false otherwise.
const tchar * GetParts(uint p) const
Reassembles any logical subset of filename parts.
const tchar * ShortName(bool forceUNC=false) const
Returns the short file path.
bool IsValid() const
Determines whether a filename is valid.
bool Move(const TFileName &newName, uint32 how=CopyAllowed)
Move (rename) the file associated with this filename, and change this name to the new name.
TFileName & operator=(const TFileName &src)
Assigns new filename or freeform to this name.
bool Copy(const TFileName &newName, bool failIfExists) const
Copy the file associated with this filename to a new file.
tstring FileStr
Holds the file filename part (no extension).
tchar * GetFullFileName()
tstring PathStr
Holds the path filename part.
TSpecialType
Construct a filename representing a special file or directory.
@ SysDir
Location of system files (LDID_SYS).
@ MachineDir
(LDID_MACHINE) currently not implemented?
@ SharedDir
Shared home directory for OS (LDID_SHARED) currently not implemented?
@ BootDir
Root dir of boot device (LDID_BOOT).
@ TempDir
Location of temporary files.
@ CurrentDir
Current working directory if any.
@ HomeDir
Home directory for OS (LDID_WIN).
@ TempFile
A temporary filename.
bool HasParts(uint p) const
Returns true if any of the parts specified by p are used.
tstring FullCanonicalName
int SetStatus(const TFileStatus &status)
Fills the status structure for the file associated with this filename with information from status.
TFileName & AddSubDir(const tstring &subdir)
bool Remove() const
Deletes this file associated with this name if possible; otherwise attempts to delete the directory a...
TFileStatus Status
Status of last attempt to find a file. See TFileStatus structure.
virtual ~TFileNameIterator()
Deletes the find file Data structure.
void * Data
Under Win32 a pointer to a WIN32_FIND_DATA structure.
virtual bool FindNext(TFileStatus &status, void *findData)
all work do here -> must fill TFileStatus structure return true on success
bool Done
Set false in the constructor.
TFileTime is a class derived from the structure FILETIME.
TFileTime()
Constructs a empty TFileTime object.
TTime()
Construct TTime with current time (seconds since Jan 1, 1901).
Definition of Common Dialog abstract base class.
#define WIN95_LONGFILENAME_MAX
Reliable platform independent header for common memory and string functions.
Object Windows Library (OWLNext Core).
void __MakeDosTime(const TTime &time, uint16 &fdate, uint16 &ftime)
uint __sys2Atr(uint32 attrib)
TTime __MakeTTime(uint16 fdate, uint16 ftime)
const int serverNamePrefixLen
uint __attr2Sys(uint attrib)
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
#define TYPESAFE_DOWNCAST(object, toClass)
tchar fullName[_MAX_PATH]