Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions

View File

@ -0,0 +1,2 @@
#include "precomp_wasabi_bfc.h"
#include "filename.h"

View File

@ -0,0 +1,26 @@
#ifndef _FILENAME_H
#define _FILENAME_H
#include <bfc/string/StringW.h>
#include <bfc/string/playstring.h>
#include <bfc/dispatch.h>
// a simple class to drag-and-drop filenames around
#define DD_FILENAME L"DD_Filename v1"
// another implementation that uses the central playstring table
class FilenamePS : private Playstring
{
public:
FilenamePS(const wchar_t *str) : Playstring(str) {}
const wchar_t *getFilename() { return getValue(); }
operator const wchar_t *() { return getFilename(); }
static const wchar_t *dragitem_getDatatype() { return DD_FILENAME; }
protected:
FilenamePS(const FilenamePS &fn) {}
FilenamePS& operator =(const FilenamePS &ps) { return *this; }
};
#endif

View File

@ -0,0 +1,129 @@
#include "precomp_wasabi_bfc.h"
#include "readdir.h"
#ifdef _WIN32
#include <shlwapi.h>
#endif
#if !defined(WIN32) && !defined(LINUX)
#error port me
#endif
//PORT
ReadDir::ReadDir( const wchar_t *_path, const wchar_t *_match, bool _skipdots ) : skipdots( _skipdots ), first( 1 ), path( _path ), match( _match )
{
files = INVALID_HANDLE_VALUE;
if ( match.isempty() )
match = MATCHALLFILES;
ZERO( data );
}
ReadDir::~ReadDir()
{
//PORT
#ifdef WIN32
if ( files != INVALID_HANDLE_VALUE ) FindClose( files );
#endif
#ifdef LINUX
if ( d != NULL ) closedir( d );
#endif
}
int ReadDir::next()
{
//PORT
#ifdef WIN32
for ( ;;)
{
if ( first )
{
wchar_t fullpath[ MAX_PATH ];
PathCombineW( fullpath, path.getValue(), match.getValue() );
files = FindFirstFileW( fullpath, &data );
}
if ( files == INVALID_HANDLE_VALUE ) return 0;
if ( first )
{
first = 0;
if ( skipdots && ( isDotDir() || isDotDotDir() ) ) continue;
return 1;
}
if ( !FindNextFileW( files, &data ) ) return 0;
if ( skipdots && ( isDotDir() || isDotDotDir() ) ) continue;
return 1;
}
#endif//WIN32
#ifdef LINUX
path.AddBackslash();
if ( first || d == NULL )
{
if ( !( d = opendir( path ) ) ) return 0;
first = 0;
}
while ( 1 )
{
de = readdir( d );
if ( !de )
{
closedir( d );
d = NULL;
return 0;
}
StringW full;
full.printf( L"%s%s", path.v(), de->d_name );
if ( stat( full, &st ) == -1 )
continue;
if ( skipdots && ( isDotDir() || isDotDotDir() ) ) continue;
if ( !Std::match( match, de->d_name ) ) continue;
return 1;
}
#endif
}
const wchar_t *ReadDir::getFilename()
{
if ( first ) if ( !next() ) return NULL;
//PORT
return data.cFileName;
}
int ReadDir::isDir()
{
//PORT
if ( files == INVALID_HANDLE_VALUE ) return 0;
return !!( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY );
}
int ReadDir::isReadonly()
{
//PORT
if ( files == INVALID_HANDLE_VALUE ) return 0;
return !!( data.dwFileAttributes & FILE_ATTRIBUTE_READONLY );
}
int ReadDir::isDotDir()
{
//PORT
if ( files == INVALID_HANDLE_VALUE ) return 0;
return ( data.cFileName[ 0 ] == '.' && data.cFileName[ 1 ] == 0 );
}
int ReadDir::isDotDotDir()
{
//PORT
if ( files == INVALID_HANDLE_VALUE ) return 0;
return ( data.cFileName[ 0 ] == '.' && data.cFileName[ 1 ] == '.' && data.cFileName[ 2 ] == 0 );
}

View File

@ -0,0 +1,48 @@
#ifndef _READDIR_H
#define _READDIR_H
#include <bfc/common.h>
#include <bfc/string/StringW.h>
/* intended use:
ReadDir dir(path);
while (dir.next()) {
const char *fn = dir.getFilename();
}
*/
class ReadDir
{
public:
ReadDir(const wchar_t *path, const wchar_t *match=NULL, bool skipdots=true);
~ReadDir();
int next(); // done when returns 0
const wchar_t *getFilename();
int isDir(); // if current file is a dir
int isReadonly(); // if current file is readonly
int isDotDir(); // if given dir iteself is being enumerated (usually ".")
int isDotDotDir(); // if parent dir of cur dir is showing (usually "..")
const wchar_t *getPath() { return path; }
private:
StringW path, match;
int skipdots, first;
//PORT
#ifdef WIN32
HANDLE files;
WIN32_FIND_DATAW data; // (shrug) so we have two? so what?
//StringW filename;
#endif
#ifdef LINUX
DIR *d;
struct dirent *de;
struct stat st;
#endif
};
#endif

View File

@ -0,0 +1,67 @@
#include "precomp_wasabi_bfc.h"
#include "recursedir.h"
RecurseDir::RecurseDir( const wchar_t *_path, const wchar_t *_match ) :
path( _path ), match( _match )
{
if ( match.isempty() ) match = Wasabi::Std::matchAllFiles();
curdir = new ReadDir( path, match );
}
RecurseDir::~RecurseDir()
{
dirstack.deleteAll();
}
int RecurseDir::next()
{
for ( ;;)
{
if ( curdir == NULL )
{ // pop one off the stack
curdir = dirstack.getLast();
if ( curdir == NULL ) return 0; // done
dirstack.removeLastItem();
}
int r = curdir->next();
if ( r <= 0 )
{
delete curdir; curdir = NULL;
continue; // get another one
}
// ok, we have a file to look at
if ( curdir->isDir() )
{ // descend into it
StringW newpath = curdir->getPath();
newpath.AppendPath( curdir->getFilename() );
dirstack.addItem( curdir ); // push the old one
curdir = new ReadDir( newpath, match ); // start new one
continue;
}
return r;
}
}
const wchar_t *RecurseDir::getPath()
{
if ( curdir == NULL )
return NULL;
return curdir->getPath();
}
const wchar_t *RecurseDir::getFilename()
{
if ( curdir == NULL )
return NULL;
return curdir->getFilename();
}
const wchar_t *RecurseDir::getOriginalPath()
{
return path;
}

View File

@ -0,0 +1,73 @@
#ifndef _RECURSEDIR_H
#define _RECURSEDIR_H
#include <bfc/wasabi_std.h>
#include <bfc/ptrlist.h>
#include <bfc/common.h>
#include <bfc/file/readdir.h>
class ReadDir;
/**
Read the contents of a directory, recursively.
Also possible to use search match patterns.
@short Recursive directory reading.
@author Nullsoft
@ver 1.0
@see ReadDir
*/
class RecurseDir {
public:
/**
Sets the directory to read and the match pattern.
If no match pattern is set, it will match against
all files.
@param path The path of the directory to read.
@param match The match pattern to use.
*/
RecurseDir(const wchar_t *path, const wchar_t *match=NULL);
/**
Deletes the directory stack.
*/
~RecurseDir();
/**
Advance to the next file.
@ret 0, No more files to read; > 0, Files left to read.
*/
int next();
/**
Restart from the top of the directory tree.
@ret 0
*/
int restart();
/**
Get the current directory path.
@ret The path.
*/
const wchar_t *getPath();
/**
Get the filename for the current file.
@ret The filename.
*/
const wchar_t *getFilename();
const wchar_t *getOriginalPath();
private:
StringW path, match;
ReadDir *curdir;
PtrList<ReadDir> dirstack;
};
#endif

View File

@ -0,0 +1,213 @@
/*
* Copyright 2000 Martin Fuchs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// 03/29/2004, f. gastellu : added _makepath and _wmakepath
#include "splitpath.h"
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WANT_UNICODE
void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext)
{
const WCHAR* end; /* end of processed string */
const WCHAR* p; /* search pointer */
const WCHAR* s; /* copy pointer */
/* extract drive name */
if (path[0] && path[1]==':') {
if (drv) {
*drv++ = *path++;
*drv++ = *path++;
*drv = L'\0';
}
} else if (drv)
*drv = L'\0';
/* search for end of string or stream separator */
for(end=path; *end && *end!=L':'; )
end++;
/* search for begin of file extension */
for(p=end; p>path && *--p!=L'\\' && *p!=L'/'; )
if (*p == L'.') {
end = p;
break;
}
if (ext)
for(s=end; *ext=*s++; )
ext++;
/* search for end of directory name */
for(p=end; p>path; )
if (*--p=='\\' || *p=='/') {
p++;
break;
}
if (name) {
for(s=p; s<end; )
*name++ = *s++;
*name = L'\0';
}
if (dir) {
for(s=path; s<p; )
*dir++ = *s++;
*dir = L'\0';
}
}
#endif
#ifdef WANT_ACP
void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
{
const char* end; /* end of processed string */
const char* p; /* search pointer */
const char* s; /* copy pointer */
/* extract drive name */
if (path[0] && path[1]==':') {
if (drv) {
*drv++ = *path++;
*drv++ = *path++;
*drv = '\0';
}
} else if (drv)
*drv = '\0';
/* search for end of string or stream separator */
for(end=path; *end && *end!=':'; )
end++;
/* search for begin of file extension */
for(p=end; p>path && *--p!='\\' && *p!='/'; )
if (*p == '.') {
end = p;
break;
}
if (ext)
for(s=end; (*ext=*s++); )
ext++;
/* search for end of directory name */
for(p=end; p>path; )
if (*--p=='\\' || *p=='/') {
p++;
break;
}
if (name) {
for(s=p; s<end; )
*name++ = *s++;
*name = '\0';
}
if (dir) {
for(s=path; s<p; )
*dir++ = *s++;
*dir = '\0';
}
}
#endif
#ifdef WANT_UNICODE
void _wmakepath( WCHAR *path, const WCHAR *drive, const WCHAR *dir, const WCHAR *fname, const WCHAR *ext ) {
if (!path) return;
*path = 0;
if (drive) {
*path++ = *drive;
*path++ = ':';
}
if (dir) {
strcat(path, dir);
if (dir[strlen(dir)-1] != '\\' && dir[strlen(dir)-1] != '/')
strcat(path, "/");
path += strlen(path);
}
if (fname) strcat(path, fname);
if (ext) {
if (*ext != '.') strcat(path++, ".");
strcat(path, ext);
}
}
#endif
#ifdef WANT_ACP
void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext ) {
if (!path) return;
*path = 0;
if (drive) {
*path++ = *drive;
*path++ = ':';
}
if (dir) {
strcat(path, dir);
if (dir[strlen(dir)-1] != '\\' && dir[strlen(dir)-1] != '/')
strcat(path, "/");
path += strlen(path);
}
if (fname) strcat(path, fname);
if (ext) {
if (*ext != '.') strcat(path++, ".");
strcat(path, ext);
}
}
#endif
/*
void main() // test splipath()
{
TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
_tsplitpath(L"x\\y", drv, dir, name, ext);
_tsplitpath(L"x\\", drv, dir, name, ext);
_tsplitpath(L"\\x", drv, dir, name, ext);
_tsplitpath(L"x", drv, dir, name, ext);
_tsplitpath(L"", drv, dir, name, ext);
_tsplitpath(L".x", drv, dir, name, ext);
_tsplitpath(L":x", drv, dir, name, ext);
_tsplitpath(L"a:x", drv, dir, name, ext);
_tsplitpath(L"a.b:x", drv, dir, name, ext);
_tsplitpath(L"W:\\/\\abc/Z:~", drv, dir, name, ext);
_tsplitpath(L"abc.EFGH:12345", drv, dir, name, ext);
_tsplitpath(L"C:/dos/command.com", drv, dir, name, ext);
}
*/
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,26 @@
#ifndef _SPLITPATH_H
#define _SPLITPATH_H
#ifndef _WIN32
#ifdef __cplusplus
extern "C" {
#endif
//#define WANT_UNICODE
#define WANT_ACP
#ifdef WANT_UNICODE
void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
void _wmakepath( WCHAR *path, const WCHAR *drive, const WCHAR *dir, const WCHAR *fname, const WCHAR *ext );
#endif
#ifdef WANT_ACP
void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext);
void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext);
#endif
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,18 @@
#ifndef _TMPNAMESTR_H
#define _TMPNAMESTR_H
#include <bfc/string/StringW.h>
class TmpNameStrW : public StringW
{
public:
TmpNameStrW()
{
wchar_t tmp[WA_MAX_PATH]=L"";
TMPNAM(tmp);
setValue(tmp);
}
};
#endif

View File

@ -0,0 +1,64 @@
// NONPORTABLE NONPORTABLE NONPORTABLE
#include "precomp_wasabi_bfc.h"
#ifdef WIN32
#include <windows.h>
#endif
#include "wildcharsenum.h"
#include <bfc/parse/pathparse.h>
#include <bfc/parse/paramparser.h>
#include <bfc/file/readdir.h>
WildcharsEnumerator::WildcharsEnumerator(const wchar_t *_selection) : selection(_selection)
{
// Then scan.
rescan();
}
WildcharsEnumerator::~WildcharsEnumerator() {
finddatalist.deleteAll();
}
int WildcharsEnumerator::getNumFiles()
{
return finddatalist.getNumItems();
}
const wchar_t *WildcharsEnumerator::enumFile(int n) {
StringW path = finddatalist.enumItem(n)->path;
if (!path.isempty())
{
enumFileString = StringPathCombine(path.getValue(), finddatalist.enumItem(n)->filename.getValue());
return enumFileString;
}
return finddatalist.enumItem(n)->filename;
}
void WildcharsEnumerator::rescan()
{
finddatalist.removeAll();
ParamParser pp(selection, L";");
for (int is = 0; is < pp.getNumItems(); is++)
{
StringW _selection = pp.enumItem(is);
PathParserW parse(_selection);
StringW path = L"";
StringW mask = L"";
for (int i=0;i<parse.getNumStrings()-1;i++)
path.AppendFolder(parse.enumString(i));
mask = parse.getLastString();
// enum files and store a list
ReadDir rd(path, mask, true);
while (rd.next()) {
finddatalist.addItem(new find_entry(rd.getPath(), rd.getFilename()));
}
}
}
int WildcharsEnumerator::isWildchars(const wchar_t *filename)
{
return (wcschr(filename, '*') || wcschr(filename, '?'));
}

View File

@ -0,0 +1,34 @@
#ifndef __WILDCHARSENUM_H
#define __WILDCHARSENUM_H
#include <bfc/ptrlist.h>
#include <bfc/string/StringW.h>
class find_entry {
public:
find_entry(const wchar_t *_path, const wchar_t *_filename) : path(_path), filename(_filename) {}
~find_entry() {}
StringW path;
StringW filename;
};
class WildcharsEnumerator
{
public:
WildcharsEnumerator(const wchar_t *_selection);
virtual ~WildcharsEnumerator();
int getNumFiles();
const wchar_t *enumFile(int n);
void rescan();
static int isWildchars(const wchar_t *filename);
private:
StringW selection;
PtrList <find_entry> finddatalist;
StringW singfiledup;
StringW enumFileString;
};
#endif