34 #include "lib/charbuf.h" 38 #include <clib/dos_protos.h> 44 CharBuffer* AmigaFilesystem::ListDirectory(
const char* path)
46 static const long int pathsize = 256;
47 CharBuffer* pathbuf =
new CharBuffer(pathsize);
51 if (GetCurrentDirName(pathbuf->GetString(), pathsize))
53 pathbuf->Append(path);
63 pathbuf->EnsureSize(StrLen(path) + 1);
64 pathbuf->Append(path);
70 lock = Lock((STRPTR)pathbuf->GetString(), ACCESS_READ);
74 CharBuffer* res =
new CharBuffer();
75 const char* msg = MSGNODIR;
76 res->EnsureSize(StrLen(msg) + StrLen(pathbuf->GetString()) + StrLen(NEWLINE) + 1);
79 res->Append(pathbuf->GetString());
86 CharBuffer* lines =
new CharBuffer();
90 FileInfoBlock* info =
new FileInfoBlock();
91 success = Examine(lock, info);
92 success = ExNext(lock, info);
97 const char* header = TXTLISTDIRHEADER;
98 lines->EnsureSize(StrLen(header) + 1);
100 lines->Append(header);
105 if (info->fib_DirEntryType < 0)
107 type = TXTLISTDIRTFILE;
111 type = TXTLISTDIRTDIR;
114 const unsigned short colsize = 12;
115 unsigned int a = StrLen(type) > colsize ? colsize : StrLen(type);
116 unsigned int b = colsize - a;
118 lines->EnsureGrowth(colsize + StrLen((
char*)info->fib_FileName) + StrLen(NEWLINE) + 1);
120 lines->Append(
' ', b);
121 lines->Append((
char*)info->fib_FileName);
122 lines->Append(NEWLINE);
124 success = ExNext(lock, info);
132 CharBuffer* AmigaFilesystem::LoadTextFile(
const char* name)
134 BPTR file = Open(
const_cast<
char*>(name), MODE_OLDFILE);
140 CharBuffer* text =
new CharBuffer();
150 text->EnsureSize(blocksize, blocks);
160 text->Append(
static_cast<
char>(c));
164 while (!eof && count < blocksize);
171 bool AmigaFilesystem::SaveTextFile(
const char* name,
const char* text)
173 BPTR file = Open(
const_cast<
char*>(name), MODE_NEWFILE);
180 char* i =
const_cast<
char*>(text);
184 r = FPutC(file, *i++);