finished reformatting ZBlkDev directory

This commit is contained in:
TomAwezome 2020-06-02 16:53:56 -04:00
parent 6d8ecb9251
commit e16edca785
7 changed files with 1083 additions and 879 deletions

View File

@ -28,7 +28,13 @@ StartOS.CC
ZMouse.CC
ZBlkDev/
DiskCheck.CC
DiskPart.CC
FileMgr.CC
MakeZBlkDev.CC
Mount.CC
ZDiskA.CC
ZDiskB.CC
/Kernel/
BlkDev/

View File

@ -1,7 +1,8 @@
#help_index "Info;File/Cmd Line (Typically);Cmd Line (Typically)"
Bool CheckDiskConfirm(Bool *_fix, Bool *_confirm)
{
if (*_fix && *_confirm) {
if (*_fix && *_confirm)
{
"Fix ";
if (!YorN)
*_fix = FALSE;
@ -10,31 +11,32 @@ Bool CheckDiskConfirm(Bool *_fix,Bool *_confirm)
return *_fix;
}
I64 RedSeaCheckDiskList(CDrive *drive,CDirEntry *tmpde1,
U8 *bits,U8 *bits2,I64 size,I64 bpc)
I64 RedSeaCheckDiskList(CDrive *drive, CDirEntry *tmpde1, U8 *bits, U8 *bits2, I64 size, I64 bpc)
{
CDirEntry *tmpde2;
I64 i, j, errs = 0;
while (tmpde1) {
while (tmpde1)
{
tmpde2 = tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR && tmpde1->sub)
errs += RedSeaCheckDiskList(drive, tmpde1->sub, bits, bits2, size, bpc);
j = (tmpde1->size + bpc - 1) / bpc;
for (i=0;i<j;i++) {
if (i+tmpde1->clus-drive->data_area>size) {
PrintErr("Invalid Clus:%s Clus:%X\n",tmpde1->full_name,
i+tmpde1->clus);
for (i = 0; i < j; i++)
{
if (i + tmpde1->clus-drive->data_area > size)
{
PrintErr("Invalid Clus:%s Clus:%X\n", tmpde1->full_name, i + tmpde1->clus);
errs++;
break;
}
if (LBts(bits,i+tmpde1->clus-drive->data_area)) {
PrintErr("Dbl Alloc:%s Clus:%X\n",tmpde1->full_name,
i+tmpde1->clus);
if (LBts(bits, i + tmpde1->clus-drive->data_area))
{
PrintErr("Dbl Alloc:%s Clus:%X\n", tmpde1->full_name, i + tmpde1->clus);
errs++;
}
if (!LBtr(bits2,i+tmpde1->clus-drive->data_area)) {
PrintErr("UnAlloc:%s Clus:%X\n",tmpde1->full_name,
i+tmpde1->clus);
if (!LBtr(bits2, i + tmpde1->clus-drive->data_area))
{
PrintErr("UnAlloc:%s Clus:%X\n", tmpde1->full_name, i + tmpde1->clus);
errs++;
}
}
@ -68,26 +70,30 @@ I64 RedSeaCheckDisk(U8 drv_let,Bool *_fix,Bool *_confirm)
j = (ptr->size + bpc - 1) / bpc;
Free(ptr2);
for (i=0;i<j;i++) {
if (i+drive->root_clus-drive->data_area>size) {
for (i = 0; i < j; i++)
{
if (i + drive->root_clus - drive->data_area > size)
{
PrintErr("Invalid Clus: RootDir Clus:%X\n", i + drive->root_clus);
errs++;
break;
}
if (LBts(bits,i+drive->root_clus-drive->data_area)) {
if (LBts(bits, i + drive->root_clus - drive->data_area))
{
PrintErr("Dbl Alloc: RootDir Clus:%X\n", i + drive->root_clus);
errs++;
}
if (!LBtr(bits2,i+drive->root_clus-drive->data_area)) {
if (!LBtr(bits2, i + drive->root_clus - drive->data_area))
{
PrintErr("UnAlloc: RootDir Clus:%X\n", i + drive->root_clus);
errs++;
}
}
errs+=RedSeaCheckDiskList(drive,FilesFind(files_find_mask,FUF_RECURSE),
bits,bits2,size,bpc);
errs += RedSeaCheckDiskList(drive, FilesFind(files_find_mask, FUF_RECURSE), bits, bits2, size, bpc);
for (i = 1; i < size; i++)
if (Bt(bits2,i)) {
if (Bt(bits2, i))
{
PrintWarn("Shouldn't Alloc Clus:%0X\n", i + drive->data_area);
errs++;
if (CheckDiskConfirm(_fix, _confirm))
@ -103,42 +109,50 @@ I64 RedSeaCheckDisk(U8 drv_let,Bool *_fix,Bool *_confirm)
return errs;
}
I64 FAT32CheckDiskList(CDrive *drive,CDirEntry *tmpde1,
U8 *bits,U32 *bits2,I64 size,I64 bpc)
I64 FAT32CheckDiskList(CDrive *drive, CDirEntry *tmpde1, U8 *bits, U32 *bits2, I64 size, I64 bpc)
{
CDirEntry *tmpde2;
I64 i, c, errs = 0;
while (tmpde1) {
while (tmpde1)
{
tmpde2 = tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR && tmpde1->sub)
errs += FAT32CheckDiskList(drive, tmpde1->sub, bits, bits2, size, bpc);
i = 0;
c = tmpde1->clus;
while (0<c<0x0FFFFFF8) {
if (c>size) {
while (0 < c < 0x0FFFFFF8)
{
if (c > size)
{
PrintErr("Invalid Clus:%s Clus:%X\n", tmpde1->full_name, c);
errs++;
break;
}
if (LBts(bits,c)) {
if (LBts(bits, c))
{
PrintErr("Dbl Alloc:%s Clus:%X\n", tmpde1->full_name, c);
errs++;
}
if (!bits2[c]) {
if (!bits2[c])
{
PrintErr("UnAlloc:%s Clus:%X\n", tmpde1->full_name, c);
errs++;
} else
}
else
bits2[c] = 0;
c = ClusNumNext(drive, c);
i++;
}
if (!(tmpde1->attr & RS_ATTR_DIR)) {
if (!(tmpde1->attr & RS_ATTR_DIR))
{
i *= bpc;
if (tmpde1->size>i) {
if (tmpde1->size>i)
{
PrintErr("Alloced File Too Short:%s\n", tmpde1->full_name);
errs++;
}
if (i>tmpde1->size+bpc-1) {
if (i > tmpde1->size + bpc - 1)
{
PrintWarn("Alloced File Too Long:%s\n", tmpde1->full_name);
errs++;
}
@ -166,30 +180,35 @@ I64 FAT32CheckDisk(U8 drv_let,Bool *_fix,Bool *_confirm)
BlkRead(drive, bits2, drive->fat1, (size * 4 + BLK_SIZE - 1) >> BLK_SIZE_BITS);
c = drive->root_clus;
while (0<c<0x0FFFFFF8) {
if (c>size) {
while (0 < c < 0x0FFFFFF8)
{
if (c > size)
{
PrintErr("Invalid Clus: RootDir Clus:%X\n", c);
errs++;
break;
}
if (LBts(bits,c)) {
if (LBts(bits, c))
{
PrintErr("Dbl Alloc: RootDir Clus:%X\n", c);
errs++;
}
if (!bits2[c]) {
if (!bits2[c])
{
PrintErr("UnAlloc: RootDir Clus:%X\n", c);
errs++;
} else
}
else
bits2[c] = 0;
c = ClusNumNext(drive, c);
}
errs+=FAT32CheckDiskList(drive,FilesFind(files_find_mask,FUF_RECURSE),
bits,bits2,size,bpc);
errs += FAT32CheckDiskList(drive, FilesFind(files_find_mask, FUF_RECURSE), bits, bits2, size, bpc);
bits2[1] = 0; //See $LK,"FAT32Format",A="MN:FAT32Format"$()
for (i = 1; i < size; i++)
if (bits2[i]) {
if (bits2[i])
{
PrintWarn("Shouldn't Alloc Clus:%0X\n", i);
errs++;
if (CheckDiskConfirm(_fix, _confirm))
@ -209,7 +228,8 @@ public I64 DiskCheck(U8 drv_let=0,Bool fix=FALSE,Bool confirm=TRUE)
//You probably want to reformat and reinstall.
I64 errs = 0;
CDrive *drive = Letter2Drive(drv_let);
switch (drive->fs_type) {
switch (drive->fs_type)
{
case FSt_REDSEA:
errs = RedSeaCheckDisk(drv_let, &fix, &confirm);
break;
@ -219,7 +239,8 @@ public I64 DiskCheck(U8 drv_let=0,Bool fix=FALSE,Bool confirm=TRUE)
default:
PrintErr("File System Not Supported\n");
}
if (errs) {
if (errs)
{
if (fix)
"It might be a little better. ";
"Copy files to another partition or CD/DVD, "
@ -232,7 +253,8 @@ public I64 DiskCheck(U8 drv_let=0,Bool fix=FALSE,Bool confirm=TRUE)
U0 RedSeaDriveView(U8 drv_let=0)
{
CDrive *drive = Letter2Drive(drv_let);
I64 lohi,c1,i,x,y,l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
I64 lohi, c1, i, x, y,
l = (GR_HEIGHT - 3 * FONT_HEIGHT) * (GR_WIDTH - FONT_WIDTH << 1),
s = drive->size + drive->drv_offset - drive->data_area;
U8 *bitmap;
CDC *dc = DCAlias;
@ -243,15 +265,18 @@ U0 RedSeaDriveView(U8 drv_let=0)
DocCursor;
DocClear;
DCFill;
try {
try
{
i = ((s + 7) >> 3 + BLK_SIZE - 1) >> BLK_SIZE_BITS;
bitmap = MAlloc(i << BLK_SIZE_BITS);
BlkRead(drive, bitmap, drive->fat1, i);
i = 0;
for (y=0;y<GR_HEIGHT-3*FONT_HEIGHT;y++) {
for (y = 0; y < GR_HEIGHT - 3 * FONT_HEIGHT; y++)
{
if (KeyScan)
break;
for (x=0;x<GR_WIDTH-FONT_WIDTH<<1;x++) {
for (x = 0; x < GR_WIDTH - FONT_WIDTH << 1; x++)
{
lohi = i * s;
c1 = lohi / l;
if (Bt(bitmap, c1))
@ -263,7 +288,8 @@ U0 RedSeaDriveView(U8 drv_let=0)
}
}
Free(bitmap);
} catch
}
catch
DriveUnlock(drive);
CharGet;
@ -274,7 +300,8 @@ U0 RedSeaDriveView(U8 drv_let=0)
U0 FAT32DriveView(U8 drv_let=0)
{
CDrive *drive = Letter2Drive(drv_let);
I64 lohi,c1,i,x,y,l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
I64 lohi, c1, i, x, y,
l = (GR_HEIGHT - 3 * FONT_HEIGHT) * (GR_WIDTH - FONT_WIDTH << 1),
s = (drive->size + drive->spc - 1) / drive->spc - (2 + drive->data_area - drive->drv_offset);
U32 *bitmap;
CDC *dc = DCAlias;
@ -285,15 +312,18 @@ U0 FAT32DriveView(U8 drv_let=0)
DocCursor;
DocClear;
DCFill;
try {
try
{
i = (s * 4 + BLK_SIZE - 1) >> BLK_SIZE_BITS;
bitmap = MAlloc(i << BLK_SIZE_BITS);
BlkRead(drive, bitmap, drive->fat1, i);
i = 0;
for (y=0;y<GR_HEIGHT-3*FONT_HEIGHT;y++) {
for (y = 0; y < GR_HEIGHT - 3 * FONT_HEIGHT; y++)
{
if (KeyScan)
break;
for (x=0;x<GR_WIDTH-FONT_WIDTH<<1;x++) {
for (x = 0; x < GR_WIDTH - FONT_WIDTH << 1; x++)
{
lohi = i * s;
c1 = lohi / l;
if (bitmap[c1])
@ -305,7 +335,8 @@ U0 FAT32DriveView(U8 drv_let=0)
}
}
Free(bitmap);
} catch
}
catch
DriveUnlock(drive);
CharGet;
@ -317,7 +348,8 @@ public U0 DriveView(U8 drv_let=0)
{//Drive view. Graph the allocation map's fragmentation.
CDrive *drive = Letter2Drive(drv_let), *old_dv = Fs->cur_dv;
Drive(drv_let);
switch (drive->fs_type) {
switch (drive->fs_type)
{
case FSt_REDSEA:
RedSeaDriveView(drv_let);
break;
@ -353,23 +385,25 @@ public U0 DiskView(U8 drv_let=0)
GrCircle(dc, h >> 1, v >> 1, radius);
j = 1;
for (i=0;i<DRIVES_NUM;i++) {
for (i = 0; i < DRIVES_NUM; i++)
{
drive = &blkdev.drvs[i];
if (bd==drive->bd && drive->fs_type) {
if (bd == drive->bd && drive->fs_type)
{
sect_start = -(drive->drv_offset * 2 * ã / (bd->max_blk + 1));
sect_end = -((drive->drv_offset + drive->size) * 2 * ã / (bd->max_blk + 1));
dc->color = BLACK;
GrLine(dc, h >> 1, v >> 1,
h >> 1 + radius * Cos(sect_start),
v >> 1 + radius * Sin(sect_start));
GrLine(dc, h >> 1, v >> 1,
h >> 1 + radius * Cos(sect_end),
v >> 1 + radius * Sin(sect_end));
attr = DriveTextAttrGet(Drive2Letter(drive));
dc->color = attr & 15;
GrPrint(dc,0,v-FONT_HEIGHT*j,"%C %-8Z",Drive2Letter(drive),
drive->fs_type,"ST_DRIVE_TYPES");
GrPrint(dc, 0, v - FONT_HEIGHT * j, "%C %-8Z", Drive2Letter(drive), drive->fs_type, "ST_DRIVE_TYPES");
dc->color.c1 = attr >> 4;
dc->color |= ROPF_DITHER;
GrFloodFill(dc,
@ -390,7 +424,8 @@ I64 RedSeaUnusedDriveSpace(U8 drv_let=0)
CDrive *drive = Letter2Drive(drv_let);
I64 res = 0, i, l;
U8 *bitmap;
try {
try
{
l = drive->size + drive->drv_offset - drive->data_area;
i = ((l + 7) >> 3 + BLK_SIZE - 1) >> BLK_SIZE_BITS;
bitmap = MAlloc(i << BLK_SIZE_BITS);
@ -399,7 +434,8 @@ I64 RedSeaUnusedDriveSpace(U8 drv_let=0)
if (!Bt(bitmap, i))
res++;
Free(bitmap);
} catch
}
catch
DriveUnlock(drive);
return res * BLK_SIZE * drive->spc;
}
@ -408,7 +444,8 @@ I64 FAT32UnusedDriveSpace(U8 drv_let=0)
CDrive *drive = Letter2Drive(drv_let);
I64 res = 0, i, l;
U32 *bitmap;
try {
try
{
l = (drive->size + drive->spc - 1) / drive->spc - (2 + drive->data_area - drive->drv_offset);
i = (l * 4 + BLK_SIZE - 1) >> BLK_SIZE_BITS;
bitmap = MAlloc(i << BLK_SIZE_BITS);
@ -417,7 +454,8 @@ I64 FAT32UnusedDriveSpace(U8 drv_let=0)
if (!bitmap[i])
res++;
Free(bitmap);
} catch
}
catch
DriveUnlock(drive);
return res * BLK_SIZE * drive->spc;
}
@ -427,7 +465,8 @@ public I64 DriveUnused(U8 drv_let=0)
U8 *old_dir = StrNew(Fs->cur_dir);
I64 res = 0;
Drive(drv_let);
switch (drive->fs_type) {
switch (drive->fs_type)
{
case FSt_REDSEA:
res = RedSeaUnusedDriveSpace(drv_let);
break;

View File

@ -22,8 +22,8 @@ drv_let=0 means add new drive that is not already mounted.
CPlannedDrive head, *tmppp;
CMasterBoot mbr;
Bool pri = TRUE;
I64 ext_base,drv_let2,pri_count=0,i,start_offset,offset,
total,remaining,cur_arg=0;
I64 ext_base, drv_let2, pri_count = 0, i, start_offset, offset, total, remaining, cur_arg = 0;
"This command does not play well\n"
"with other operating systems.\n"
"You really should use another\n"
@ -40,38 +40,42 @@ drv_let=0 means add new drive that is not already mounted.
if (drv_let && !Letter2BlkDev(drv_let, FALSE))
drv_let = 0;
if (!drv_let && !(drv_let=Mount(TRUE)) ||
!(bd=Letter2BlkDev(drv_let,FALSE)) || bd->type!=BDT_ATA)
if (!drv_let && !(drv_let = Mount(TRUE)) || !(bd = Letter2BlkDev(drv_let, FALSE)) || bd->type != BDT_ATA)
return 0;
total = bd->max_blk + 1;
QueueInit(&head);
drv_let2 = bd->first_drive_let;
remaining = FloorU64(bd->max_blk + 1, ROUND_DRIVE_TO);
while (FloorU64(remaining,ROUND_DRIVE_TO)>=ROUND_DRIVE_TO) {
while (FloorU64(remaining, ROUND_DRIVE_TO) >= ROUND_DRIVE_TO)
{
tmppp = MAlloc(sizeof(CPlannedDrive));
do {
do
{
"$$RED$$Partition %C$$FG$$\n", drv_let2;
tmppp->pri = FALSE;
if (pri) {
if (pri)
{
"Primary Partition";
if (argc>cur_arg || YorN) {
if (argc>cur_arg || YorN)
{
pri_count++;
tmppp->pri = TRUE;
if (pri_count == 3)
pri = FALSE;
} else
}
else
pri = FALSE;
}
"\nBlocks Remaining:%d (0x%X)\n",
remaining-DRIVE_HEADER,remaining-DRIVE_HEADER;
"\nBlocks Remaining:%d (0x%X)\n", remaining - DRIVE_HEADER, remaining - DRIVE_HEADER;
if (argc > cur_arg)
tmppp->size = MinI64(CeilU64(MaxI64(remaining, DRIVE_HEADER), ROUND_DRIVE_TO),
CeilU64(argv[cur_arg++](F64) * total, ROUND_DRIVE_TO));
else
tmppp->size=CeilU64(I64Get("Size in Blocks :",
remaining-DRIVE_HEADER)+DRIVE_HEADER,ROUND_DRIVE_TO);
} while (!(ROUND_DRIVE_TO<=tmppp->size<=FloorU64(remaining,ROUND_DRIVE_TO)));
tmppp->size = CeilU64(I64Get("Size in Blocks :", remaining - DRIVE_HEADER) + DRIVE_HEADER, ROUND_DRIVE_TO);
}
while (!(ROUND_DRIVE_TO <= tmppp->size <= FloorU64(remaining, ROUND_DRIVE_TO)));
QueueInsert(tmppp, head.last);
remaining -= tmppp->size;
drv_let2++;
@ -80,7 +84,8 @@ drv_let=0 means add new drive that is not already mounted.
"\n\n!!! Repartition Drive !!!\n\n";
tmppp = head.next;
drv_let2 = bd->first_drive_let;
while (tmppp!=&head) {
while (tmppp != &head)
{
"Drive %C:%08X ", drv_let2, tmppp->size;
if (tmppp->pri)
"Primary\n";
@ -97,7 +102,8 @@ drv_let=0 means add new drive that is not already mounted.
MemSet(&mbr, 0, BLK_SIZE);
mbr.signature = 0xAA55;
offset = 0;
for (i=0;i<pri_count;i++) {
for (i = 0; i < pri_count; i++)
{
mbr.p[i].active = 0x80;
mbr.p[i].start_head = 0;
mbr.p[i].start_cyl = 0x101;
@ -110,8 +116,10 @@ drv_let=0 means add new drive that is not already mounted.
remaining -= tmppp->size;
tmppp = tmppp->next;
}
if (!i) i++;
if (tmppp!=&head) {
if (!i)
i++;
if (tmppp != &head)
{
mbr.p[i].active = 0x80;
mbr.p[i].start_head = 0;
mbr.p[i].start_cyl = 0x101;
@ -124,7 +132,8 @@ drv_let=0 means add new drive that is not already mounted.
}
ATAWriteBlks(bd, &mbr, 0, 1);
while (tmppp!=&head) {
while (tmppp != &head)
{
start_offset = offset;
MemSet(&mbr, 0, BLK_SIZE);
mbr.signature = 0xAA55;
@ -139,7 +148,8 @@ drv_let=0 means add new drive that is not already mounted.
mbr.p[0].size = tmppp->size - DRIVE_HEADER;
offset += tmppp->size;
tmppp = tmppp->next;
if (tmppp!=&head) {
if (tmppp != &head)
{
mbr.p[1].active = 0x80;
mbr.p[1].start_head = 0;
mbr.p[1].start_cyl = 0x101;
@ -158,7 +168,8 @@ drv_let=0 means add new drive that is not already mounted.
Format(i,, FALSE);
pd_done:
while (head.next!=&head) {
while (head.next != &head)
{
tmppp = head.next;
QueueRemove(tmppp);
Free(tmppp);

View File

@ -1,14 +1,18 @@
#help_index "DolDoc/Output;StdOut/DolDoc"
U0 DirFileDoc(CDoc *doc, CDirEntry *tmpde)
{
while (tmpde) {
if (tmpde->attr & RS_ATTR_DIR) {
while (tmpde)
{
if (tmpde->attr & RS_ATTR_DIR)
{
tmpde->user_data = DocPrint(doc, "$$TR,\"%s\",U=0x%X$$", tmpde->name, tmpde);
DocPrint(doc, "\n$$ID,+2$$");
if (tmpde->sub)
DirFileDoc(doc, tmpde->sub);
DocPrint(doc, "$$ID,-2$$");
} else {
}
else
{
tmpde->user_data = DocPrint(doc, "$$MU,\"%s\",U=0x%X$$", tmpde->name, tmpde);
DocPrint(doc, "\n");
}
@ -33,10 +37,14 @@ CFMUncollapsedList *FMCollectUncollapsedList(CDoc *doc)
CDocEntry *doc_e = doc->head.next;
CFMUncollapsedList *res = NULL, *tmpc;
CDirEntry *tmpde;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TREE) {
if (!(doc_e->de_flags&DOCEF_CHECKED_COLLAPSED)) {
if (tmpde=doc_e->user_data) {
while (doc_e != doc)
{
if (doc_e->type_u8 == DOCT_TREE)
{
if (!(doc_e->de_flags & DOCEF_CHECKED_COLLAPSED))
{
if (tmpde = doc_e->user_data)
{
tmpc = MAlloc(sizeof(CFMUncollapsedList));
tmpc->next = res;
res = tmpc;
@ -49,47 +57,60 @@ CFMUncollapsedList *FMCollectUncollapsedList(CDoc *doc)
return res;
}
U0 FMMarkUncollapsed(CDoc *doc,CFMUncollapsedList *tmpc,
U8 *cur_entry,U8 *next_entry)
U0 FMMarkUncollapsed(CDoc *doc, CFMUncollapsedList *tmpc, U8 *cur_entry, U8 *next_entry)
{
CDocEntry *doc_e = doc->head.next;
CFMUncollapsedList *tmpc1;
CDirEntry *tmpde;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TREE) {
while (doc_e != doc)
{
if (doc_e->type_u8 == DOCT_TREE)
{
tmpde = doc_e->user_data;
tmpc1 = tmpc;
while (tmpc1) {
if (!StrCompare(tmpc1->name,tmpde->full_name)) {
while (tmpc1)
{
if (!StrCompare(tmpc1->name, tmpde->full_name))
{
doc_e->de_flags &= ~DOCEF_CHECKED_COLLAPSED;
break;
}
tmpc1 = tmpc1->next;
}
if (cur_entry) {
if (!StrNCompare(cur_entry,tmpde->full_name,StrLen(tmpde->full_name))) {
if (cur_entry)
{
if (!StrNCompare(cur_entry, tmpde->full_name, StrLen(tmpde->full_name)))
{
doc->cur_entry = doc_e;
if (StrLen(tmpde->full_name) == StrLen(cur_entry))
cur_entry = NULL;
} else if (next_entry) {
if (!StrNCompare(next_entry,
tmpde->full_name,StrLen(tmpde->full_name))) {
}
else if (next_entry)
{
if (!StrNCompare(next_entry, tmpde->full_name, StrLen(tmpde->full_name)))
{
doc->cur_entry = doc_e;
if (StrLen(tmpde->full_name) == StrLen(next_entry))
cur_entry = NULL;
}
}
}
} else if (doc_e->type_u8==DOCT_MENU_VAL) {
}
else if (doc_e->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_e->user_data;
if (cur_entry) {
if (!StrNCompare(cur_entry,tmpde->full_name,StrLen(tmpde->full_name))) {
if (cur_entry)
{
if (!StrNCompare(cur_entry, tmpde->full_name, StrLen(tmpde->full_name)))
{
doc->cur_entry = doc_e;
if (StrLen(tmpde->full_name) == StrLen(cur_entry))
cur_entry = NULL;
} else if (next_entry) {
if (!StrNCompare(next_entry,
tmpde->full_name,StrLen(tmpde->full_name))) {
}
else if (next_entry)
{
if (!StrNCompare(next_entry, tmpde->full_name, StrLen(tmpde->full_name)))
{
doc->cur_entry = doc_e;
if (StrLen(tmpde->full_name) == StrLen(next_entry))
cur_entry = NULL;
@ -104,7 +125,8 @@ U0 FMMarkUncollapsed(CDoc *doc,CFMUncollapsedList *tmpc,
U0 FMDelUncollapsedList(CFMUncollapsedList *tmpc)
{
CFMUncollapsedList *tmpc1;
while (tmpc) {
while (tmpc)
{
tmpc1 = tmpc->next;
Free(tmpc->name);
Free(tmpc);
@ -130,9 +152,11 @@ CDirEntry *FMRebuildDocDrive(U8 drv_let,CDoc *doc,CDirEntry **_head,Bool init)
*_head = tmpde;
DocPrint(doc, "\n$$ID,+2$$");
DocBottom(doc);
if (init) {
if (init)
{
DirFileDoc(doc, tmpde1);
while (tmpde1) {
while (tmpde1)
{
tmpde1->parent = tmpde;
tmpde1 = tmpde1->next;
}
@ -155,7 +179,8 @@ U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
CDirEntry *tmpde, *tmpde1, *cur_tree_entry;
if (!doc)
parent_doc = DocPut;
else {
else
{
parent_doc = doc->parent_doc;
Fs->put_doc = Fs->display_doc = NULL;
DocUnlock(doc);
@ -170,18 +195,23 @@ U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
tmpde = NULL;
if (doc_ce != doc)
doc_ce = doc_ce->next;
while (doc_ce!=doc) {
while (doc_ce != doc)
{
if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
tmpde1 = tmpde->parent;
while (tmpde1) {
if (tmpde1==cur_tree_entry) {
while (tmpde1)
{
if (tmpde1 == cur_tree_entry)
{
tmpde = NULL;
break;
} else
}
else
tmpde1 = tmpde1->parent;
}
if (tmpde)
@ -195,7 +225,8 @@ U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
tmpc = FMCollectUncollapsedList(doc);
DocDel(doc);
}
if (*_head) {
if (*_head)
{
DirTreeDel(*_head);
*_head = NULL;
}
@ -203,7 +234,8 @@ U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
doc->desc = 'FileMan';
doc->parent_doc = parent_doc;
doc->flags |= DOCF_FORM;
switch (mode) {
switch (mode)
{
case FM_NORMAL:
DocPrint(doc,"$$PURPLE$$File Manager\n\n"
"$$LK,\"Click for Help\",A=\"FI:::/Doc/FileMgr.DD\"$$\n\n");
@ -218,16 +250,20 @@ U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
break;
}
DocPrint(doc, "$$LTBLUE$$");
for (i=0;i<DRIVES_NUM;i++) {
for (i = 0; i < DRIVES_NUM; i++)
{
drive = &blkdev.drvs[i];
if (drive->bd->type==BDT_ATAPI) {
if (drive->bd->type == BDT_ATAPI)
{
if (drive->bd->flags & BDF_INITIALIZED)
tmpde = FMRebuildDocDrive(Drive2Letter(drive), doc, _head, TRUE);
else {
else
{
tmpde = FMRebuildDocDrive(Drive2Letter(drive), doc, _head, FALSE);
tmpde->user_data2 |= DEF2_NOT_INITIALIZED;
}
} else if (drive->fs_type==FSt_REDSEA || drive->fs_type==FSt_FAT32)
}
else if (drive->fs_type == FSt_REDSEA || drive->fs_type == FSt_FAT32)
FMRebuildDocDrive(Drive2Letter(drive), doc, _head, TRUE);
}
DocTop(doc);
@ -247,24 +283,32 @@ U0 FMRename(CDoc *doc)
CEdFileName fn;
CDocEntry *doc_e = doc->cur_entry;
CDirEntry *tmpde = NULL, *parent;
if (doc_e->type_u8==DOCT_MENU_VAL) {
if (doc_e->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_e->user_data;
if (parent=tmpde->parent) {
if (parent = tmpde->parent)
{
Cd(parent->full_name);
StrCopy(fn.name, tmpde->name);
if (DocForm(&fn)) {
if (DocForm(&fn))
{
Silent;
Move(tmpde->name, fn.name);
Silent(OFF);
}
}
} else if (doc_e->type_u8==DOCT_TREE) {
}
else if (doc_e->type_u8 == DOCT_TREE)
{
tmpde = doc_e->user_data;
if (parent=tmpde->parent) {
if (parent = tmpde->parent)
{
Cd(parent->full_name);
StrCopy(fn.name, tmpde->name);
if (DocForm(&fn)) {
if (StrCompare(tmpde->name,fn.name)) {
if (DocForm(&fn))
{
if (StrCompare(tmpde->name, fn.name))
{
Silent;
if (CopyTree(tmpde->name, fn.name))
DelTree(tmpde->name);
@ -281,20 +325,26 @@ U0 FMMkDir(CDoc *doc)
CDocEntry *doc_e = doc->cur_entry;
CDirEntry *tmpde = NULL, *parent;
*fn.name = 0;
if (doc_e->type_u8==DOCT_MENU_VAL) {
if (doc_e->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_e->user_data;
if (parent=tmpde->parent) {
if (parent = tmpde->parent)
{
Cd(parent->full_name);
if (DocForm(&fn)) {
if (DocForm(&fn))
{
Silent;
DirMake(fn.name);
Silent(OFF);
}
}
} else if (doc_e->type_u8==DOCT_TREE) {
}
else if (doc_e->type_u8 == DOCT_TREE)
{
tmpde = doc_e->user_data;
Cd(tmpde->full_name);
if (DocForm(&fn)) {
if (DocForm(&fn))
{
Silent;
DirMake(fn.name);
Silent(OFF);
@ -307,7 +357,8 @@ U0 FMDelete(CDoc *doc)
U8 *st;
CDocEntry *doc_ce = doc->cur_entry;
CDirEntry *tmpde;
if (doc_ce->type_u8==DOCT_MENU_VAL) {
if (doc_ce->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_ce->user_data;
Silent;
st = MStrPrint("Delete: %s", tmpde->full_name);
@ -315,7 +366,9 @@ U0 FMDelete(CDoc *doc)
Del(tmpde->full_name);
Free(st);
Silent(OFF);
} else if (doc_ce->type_u8==DOCT_TREE) {
}
else if (doc_ce->type_u8 == DOCT_TREE)
{
tmpde = doc_ce->user_data;
Silent;
st = MStrPrint("Delete: %s", tmpde->full_name);
@ -334,7 +387,8 @@ U0 FMChangeDisk(CDoc *doc)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
while (tmpde->parent)
tmpde = tmpde->parent;
Silent;
@ -360,7 +414,8 @@ U0 FMUnmount(CDoc *doc)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
while (tmpde->parent)
tmpde = tmpde->parent;
drv_let = *tmpde->full_name;
@ -378,11 +433,13 @@ U0 FMFormatDrive(CDoc *doc)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
while (tmpde->parent)
tmpde = tmpde->parent;
st = MStrPrint("Format Drive '%c'?\nAre You Sure?\n", *tmpde->full_name);
if (PopUpCancelOk(st)) {
if (PopUpCancelOk(st))
{
Silent;
Format(*tmpde->full_name,, FALSE);
Silent(OFF);
@ -399,10 +456,12 @@ U0 FMMakeISO(CDoc *doc)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
if (doc_ce->type_u8 == DOCT_MENU_VAL)
tmpde = tmpde->parent;
if (tmpde && *tmpde->full_name) {
if (tmpde && *tmpde->full_name)
{
Silent;
RedSeaISO(, tmpde->full_name);
Silent(OFF);
@ -418,7 +477,8 @@ U0 FMBurnISO(CDoc *doc)
tmpde = doc_ce->user_data;
else
tmpde = NULL;
if (tmpde) {
if (tmpde)
{
while (tmpde->parent)
tmpde = tmpde->parent;
Silent;
@ -441,22 +501,29 @@ U0 FMCopy(CDoc *doc)
tmpde1 = tmpde1->parent;
else if (doc_ce->type_u8 != DOCT_TREE)
tmpde1 = NULL;
if (tmpde1) {
while (doc_e!=doc2) {
if (doc_e->type_u8==DOCT_MENU_VAL) {
if (tmpde1)
{
while (doc_e != doc2)
{
if (doc_e->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_e->user_data;
tmpde->user_data2 |= DEF2_PROCESSED;
tmpde2 = tmpde->parent;
if (!tmpde2 || !(tmpde2->user_data2&DEF2_PROCESSED)) {
if (!tmpde2 || !(tmpde2->user_data2 & DEF2_PROCESSED))
{
Silent;
Copy(tmpde->full_name, tmpde1->full_name);
Silent(OFF);
}
} else if (doc_e->type_u8==DOCT_TREE) {
}
else if (doc_e->type_u8 == DOCT_TREE)
{
tmpde = doc_e->user_data;
tmpde->user_data2 |= DEF2_PROCESSED;
tmpde2 = tmpde->parent;
if (!tmpde2 || !(tmpde2->user_data2&DEF2_PROCESSED)) {
if (!tmpde2 || !(tmpde2->user_data2 & DEF2_PROCESSED))
{
Silent;
if (*tmpde1->name)
st = MStrPrint("%s/%s", tmpde1->full_name, tmpde->name);
@ -492,7 +559,9 @@ I64 PopUpFMRight(U8 *header=NULL,U8 *footer=NULL)
{
I64 i;
CDoc *doc = DocNew;
if (header) DocPrint(doc,"%s",header);
if (header)
DocPrint(doc, "%s",header);
DocPrint(doc, "$$CM+LX,1,1$$$$BT,\"INCLUDE \",LE=FMR_INCLUDE$$"
"$$CM+LX,29,0$$$$BT,\"ZENITH INCLUDE \",LE=FMR_ZENITH_INCLUDE$$"
"$$CM+LX,1,3 $$$$BT,\"DELETE \",LE=FMR_DELETE$$"
@ -507,7 +576,9 @@ I64 PopUpFMRight(U8 *header=NULL,U8 *footer=NULL)
"$$CM+LX,29,0$$$$BT,\"BURN ISO (CD/DVD) FILE \",LE=FMR_BURN_ISO$$"
"$$CM+LX,1,3 $$$$BT,\"HELP \",LE=FMR_HELP$$"
"$$CM+LX,29,0$$$$BT,\"CANCEL \",LE=DOCM_CANCEL$$\n");
if (footer) DocPrint(doc,"%s",footer);
if (footer)
DocPrint(doc, "%s", footer);
i = PopUpMenu(doc);
DocDel(doc);
return i;
@ -515,7 +586,8 @@ I64 PopUpFMRight(U8 *header=NULL,U8 *footer=NULL)
U0 FMRightClick()
{
switch (PopUpFMRight) {
switch (PopUpFMRight)
{
case FMR_INCLUDE:
Message(MESSAGE_KEY_DOWN, 0, 0x3F0000003F);
break;
@ -563,7 +635,8 @@ U0 (*fp_old_final_screen_update)(CDC *dc);
U0 FMFinalScreenUpdate(CDC *dc)
{
if (fm_mouse_str) {
if (fm_mouse_str)
{
dc->color = LTRED;
GrPrint(dc, mouse.pos.x, mouse.pos.y, "%s", fm_mouse_str);
}
@ -585,18 +658,23 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
FMRebuildDoc(&doc, &head, mode);
if (tmpde1 = Cd2DirEntry(head, old_cur_dir))
doc->cur_entry = tmpde1->user_data;
while (tmpde1) {
while (tmpde1)
{
if (tmpde1->attr & RS_ATTR_DIR)
tmpde1->user_data(CDocEntry *)->de_flags &= ~DOCEF_CHECKED_COLLAPSED;
tmpde1 = tmpde1->parent;
}
do {
do
{
DocUnlock(doc);
do message_code = MessageGet(&arg1, &arg2,
1 << MESSAGE_KEY_DOWN | 1 << MESSAGE_MS_L_DOWN | 1 << MESSAGE_MS_L_UP | 1 << MESSAGE_MS_R_UP);
while (Fs != sys_focus_task);
DocLock(doc);
switch (message_code) {
switch (message_code)
{
case MESSAGE_MS_R_UP:
DocUnlock(doc);
FMRightClick;
@ -608,45 +686,57 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
gr.fp_final_screen_update = &FMFinalScreenUpdate;
break;
case MESSAGE_MS_L_UP:
if (doc_ce) {
if (doc_ce)
{
gr.fp_final_screen_update = fp_old_final_screen_update;
if (WinCursorPosSet(Fs,arg1+Fs->pix_left+Fs->scroll_x,
arg2+Fs->pix_top+Fs->scroll_y,TRUE)) {
if (WinCursorPosSet(Fs, arg1 + Fs->pix_left + Fs->scroll_x, arg2 + Fs->pix_top + Fs->scroll_y, TRUE))
{
doc_e = doc->cur_entry;
if (doc_e!=doc_ce) {
if (doc_e != doc_ce)
{
st2 = NULL;
if (doc_e->type_u8==DOCT_MENU_VAL) {
if (doc_e->type_u8 == DOCT_MENU_VAL)
{
tmpde1 = doc_e->user_data;
if (tmpde1 = tmpde1->parent)
st2 = StrNew(tmpde1->full_name);
} else if (doc_e->type_u8==DOCT_TREE) {
}
else if (doc_e->type_u8 == DOCT_TREE)
{
tmpde1 = doc_e->user_data;
st2 = StrNew(tmpde1->full_name);
}
if (st2 && doc_ce->type_u8==DOCT_MENU_VAL) {
if (st2 && doc_ce->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc_ce->user_data;
Silent;
Move(tmpde->full_name, st2);
Silent(OFF);
FMRebuildDoc(&doc, &head, mode);
} else if (st2 && doc_ce->type_u8==DOCT_TREE) {
}
else if (st2 && doc_ce->type_u8 == DOCT_TREE)
{
tmpde = doc_ce->user_data;
okay = TRUE;
tmpde2 = tmpde1;
while (tmpde2) {
while (tmpde2)
{
if (tmpde2 != tmpde)
tmpde2 = tmpde2->parent;
else {
else
{
okay = FALSE;
break;
}
}
if (okay) {
if (okay)
{
if (*tmpde1->name)
st = MStrPrint("%s/%s", tmpde1->full_name, tmpde->name);
else
st = MStrPrint("%s%s", tmpde1->full_name, tmpde->name);
if (StrCompare(tmpde->full_name,st)) {
if (StrCompare(tmpde->full_name, st))
{
Silent;
CopyTree(tmpde->full_name, st);
DelTree(tmpde->full_name);
@ -658,8 +748,10 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
}
Free(st2);
FlushMessages;
} else
if (doc_e->type_u8==DOCT_MENU_VAL) {
}
else
if (doc_e->type_u8 == DOCT_MENU_VAL)
{
DocUnlock(doc);
Ed(doc_e->user_data(CDirEntry *)->full_name);
DocLock(doc);
@ -670,11 +762,14 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
break;
case MESSAGE_KEY_DOWN:
doc_ce = NULL;
ch=arg1; sc=arg2;
ch = arg1;
sc = arg2;
if (sc.u8[0] == SC_DELETE && !(sc & (SCF_SHIFT | SCF_CTRL)))
ch = CH_CTRLY;
if (ch && sc&SCF_ALT) goto fm_regular_key;
switch (ch) {
if (ch && sc & SCF_ALT)
goto fm_regular_key;
switch (ch)
{
case '\n':
DocUnlock(doc);
FMRightClick;
@ -718,11 +813,13 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
case CH_SHIFT_ESC:
break;
case CH_SPACE:
if (doc->cur_entry->type_u8==DOCT_MENU_VAL) {
if (doc->cur_entry->type_u8 == DOCT_MENU_VAL)
{
DocUnlock(doc);
Ed(doc->cur_entry->user_data(CDirEntry *)->full_name);
DocLock(doc);
} else
}
else
goto fm_regular_key;
break;
case CH_ESC:
@ -730,20 +827,24 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
tmpde = doc_ce->user_data;
if (mode == FM_PICK_FILE && doc_ce->type_u8 == DOCT_MENU_VAL)
res = StrNew(tmpde->full_name, mem_task);
else if (mode==FM_PICK_DIR) {
else if (mode == FM_PICK_DIR)
{
if (doc_ce->type_u8 == DOCT_TREE)
res = StrNew(tmpde->full_name, mem_task);
else if (doc_ce->type_u8==DOCT_MENU_VAL &&
(tmpde=tmpde->parent))
else if (doc_ce->type_u8 == DOCT_MENU_VAL && (tmpde = tmpde->parent))
res = StrNew(tmpde->full_name, mem_task);
}
break;
default:
if (sc.u8[0]==SC_INS && sc&SCF_SHIFT && !(sc&SCF_CTRL)) {
if (sc.u8[0] == SC_INS && sc & SCF_SHIFT && !(sc & SCF_CTRL))
{
FMCopy(doc);
FMRebuildDoc(&doc, &head, mode);
} else if (sc.u8[0]==SC_F5) {
if (doc->cur_entry->type_u8==DOCT_MENU_VAL) {
}
else if (sc.u8[0] == SC_F5)
{
if (doc->cur_entry->type_u8 == DOCT_MENU_VAL)
{
tmpde = doc->cur_entry->user_data;
DocUnlock(doc);
if (sc & SCF_SHIFT)
@ -752,7 +853,9 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
PopUpFile(tmpde->full_name);
DocLock(doc);
}
} else {
}
else
{
fm_regular_key:
DocUnlock(doc);
PutKey(ch, sc);
@ -761,7 +864,9 @@ fm_regular_key:
}
break;
}
} while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
}
while (ch != CH_ESC && ch != CH_SHIFT_ESC);
gr.fp_final_screen_update = fp_old_final_screen_update;
Fs->put_doc = old_put_doc;
Fs->display_doc = old_display_doc;

View File

@ -8,9 +8,11 @@ public U8 *DBlk(I64 blk,Bool write=FALSE)
BlkRead(Fs->cur_dv, buf, blk, 1);
DocD(buf, BLK_SIZE);
if (write) {
if (write)
{
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
if (View)
{
"Write\n";
BlkWrite(Fs->cur_dv, buf, blk, 1);
}
@ -29,9 +31,11 @@ public U8 *DClus(I64 c,Bool write=FALSE,I64 num=0)
ClusRead(Fs->cur_dv, buf, c, 1);
"Clus:%X\n", c;
DocD(buf, Fs->cur_dv->spc << BLK_SIZE_BITS);
if (write) {
if (write)
{
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
if (View)
{
"Write\n";
ClusWrite(Fs->cur_dv, buf, c, 1);
}
@ -45,11 +49,14 @@ public U8 *Dump(U8 *filename,Bool write=FALSE)
//be written when you press <ESC>.
U8 *buf;
I64 size;
if (buf=FileRead(filename,&size)) {
if (buf = FileRead(filename,&size))
{
DocD(buf, size);
if (write) {
if (write)
{
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
if (View)
{
"Write\n";
FileWrite(filename, buf, size);
}
@ -69,11 +76,15 @@ public Bool Copy(U8 *src_files_find_mask,U8 *dst_files_find_mask=".")
U8 *st;
if (!(tmpde1 = FilesFind(src_files_find_mask, FUF_CLUS_ORDER)))
return FALSE;
if (IsDir(dst_files_find_mask)) {
if (dirc=DirContextNew(dst_files_find_mask,TRUE)) {
if (IsDir(dst_files_find_mask))
{
if (dirc = DirContextNew(dst_files_find_mask, TRUE))
{
tmpde = tmpde1;
while (tmpde) {
if (!(tmpde->attr & RS_ATTR_DIR)) {
while (tmpde)
{
if (!(tmpde->attr & RS_ATTR_DIR))
{
st = FileNameAbs(tmpde->name);
if (!CopySingle(tmpde->full_name, st))
res = FALSE;
@ -85,7 +96,9 @@ public Bool Copy(U8 *src_files_find_mask,U8 *dst_files_find_mask=".")
}
DirTreeDel(tmpde1);
return res;
} else {
}
else
{
DirTreeDel(tmpde1);
return CopySingle(src_files_find_mask, dst_files_find_mask);
}
@ -93,7 +106,8 @@ public Bool Copy(U8 *src_files_find_mask,U8 *dst_files_find_mask=".")
public Bool Move(U8 *f1, U8 *f2)
{//Move files from one location to another or rename.
if (Copy(f1,f2)) {
if (Copy(f1, f2))
{
Del(f1);
return TRUE;
}
@ -104,14 +118,17 @@ I64 CopyTree2(CDirEntry *tmpde,I64 src_dir_len,I64 dst_dir_len,U8 *dst_dir)
{
U8 *st;
I64 res = 1;
while (tmpde) {
while (tmpde)
{
st = MAlloc(StrLen(tmpde->full_name) + dst_dir_len + 2);
MemCopy(st, dst_dir, dst_dir_len);
StrCopy(st + dst_dir_len, tmpde->full_name + src_dir_len);
if (tmpde->attr & RS_ATTR_DIR) {
if (tmpde->attr & RS_ATTR_DIR)
{
DirMake(st, LinkedListCount(tmpde->sub));
res += CopyTree2(tmpde->sub, src_dir_len, dst_dir_len, dst_dir);
} else
}
else
if (CopySingle(tmpde->full_name, st))
res++;
Free(st);
@ -119,8 +136,7 @@ I64 CopyTree2(CDirEntry *tmpde,I64 src_dir_len,I64 dst_dir_len,U8 *dst_dir)
}
return res;
}
public I64 CopyTree(U8 *src_files_find_mask,U8 *dst_files_find_mask,
Bool no_mask=TRUE)
public I64 CopyTree(U8 *src_files_find_mask, U8 *dst_files_find_mask, Bool no_mask=TRUE)
{//Copy directory tree.
//Returns the count of copied files (not dirs).
CDirContext *dirc;
@ -131,23 +147,28 @@ public I64 CopyTree(U8 *src_files_find_mask,U8 *dst_files_find_mask,
st1 = DirNameAbs(src_files_find_mask);
st2 = DirNameAbs(dst_files_find_mask);
i1 = StrLen(st1);
if (!StrNCompare(st1,st2,i1) && (st2[i1]=='/' || !st2[i1]) ) {
if (!StrNCompare(st1, st2, i1) && (st2[i1] == '/' || !st2[i1]))
{
Free(st1);
Free(st2);
return 0;
}
Free(st1);
Free(st2);
if (dirc=DirContextNew(src_files_find_mask,TRUE,,no_mask)) {
if (dirc = DirContextNew(src_files_find_mask, TRUE,, no_mask))
{
tmpde = FilesFind(dirc->mask, FUF_RECURSE);
st1 = DirCur;
DirContextDel(dirc);
i1 = StrLen(st1);
if (i1==3) i1--;
if (dirc=DirContextNew(dst_files_find_mask,TRUE,TRUE)) {
if (i1 == 3)
i1--;
if (dirc = DirContextNew(dst_files_find_mask, TRUE, TRUE))
{
st2 = DirCur;
i2 = StrLen(st2);
if (i2==3) i2--;
if (i2 == 3)
i2--;
res = CopyTree2(tmpde, i1, i2, st2);
DirContextDel(dirc);
Free(st2);
@ -162,9 +183,11 @@ I64 DelTreeDirs(CDirEntry *tmpde1)
{
I64 res = 0;
CDirEntry *tmpde2;
while (tmpde1) {
while (tmpde1)
{
tmpde2 = tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR) {
if (tmpde1->attr & RS_ATTR_DIR)
{
if (tmpde1->sub)
res += DelTreeDirs(tmpde1->sub);
res += Del(tmpde1->full_name, TRUE, TRUE);
@ -178,12 +201,15 @@ I64 DelTreeFiles(CDirEntry *tmpde1)
{
I64 res = 0;
CDirEntry *tmpde2;
while (tmpde1) {
while (tmpde1)
{
tmpde2 = tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR) {
if (tmpde1->attr & RS_ATTR_DIR)
{
if (tmpde1->sub)
res += DelTreeFiles(tmpde1->sub);
} else
}
else
res += Del(tmpde1->full_name, FALSE, TRUE);
DirEntryDel(tmpde1);
tmpde1 = tmpde2;
@ -195,11 +221,13 @@ public I64 DelTree(U8 *files_find_mask,U8 *fu_flags=NULL)
I64 res = 0, fuf_flags = 0;
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), "+r");
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), fu_flags);
if (IsDir(files_find_mask)) {
if (IsDir(files_find_mask))
{
res = DelTreeDirs(FilesFind(files_find_mask, fuf_flags));
res += Del(files_find_mask, TRUE, TRUE);
res += Del(files_find_mask, FALSE, TRUE);
} else
}
else
res = DelTreeFiles(FilesFind(files_find_mask, fuf_flags));
return res;
}
@ -209,11 +237,13 @@ U0 TouchFile(U8 *filename,U8 *attr,CDate cdt=I64_MIN)
CDrive *drive = Letter2Drive(*filename);
CDirEntry de;
U8 *cur_dir = StrNew(filename), buf[STR_LEN];
if (FileFind(filename,&de,FUF_JUST_FILES)) {
if (FileFind(filename, &de, FUF_JUST_FILES))
{
Free(de.full_name);
if (!StrCompare(attr, "+?"))
"%-48ts %s\n", filename, FlagsStrPrint(buf, Define("ST_FILE_ATTRS"), de.attr);
else {
else
{
StrFirstRemove(cur_dir, ":");
StrLastRemove(cur_dir, "/");
if (!*cur_dir)
@ -225,12 +255,12 @@ U0 TouchFile(U8 *filename,U8 *attr,CDate cdt=I64_MIN)
de.datetime = cdt;
DirNew(drive, cur_dir, &de, FALSE);
}
} else
}
else
PrintErr("File not found: \"%s\".\n", filename);
Free(cur_dir);
}
public U0 Touch(U8 *files_find_mask="*",U8 *attr="+?",
U8 *fu_flags=NULL,CDate cdt=I64_MIN)
public U0 Touch(U8 *files_find_mask="*", U8 *attr="+?", U8 *fu_flags=NULL, CDate cdt=I64_MIN)
{/*Touch file attributes and DateTime.
Default lists attributes.
attr: "+?" =show current
@ -244,7 +274,8 @@ Touch(filename,"",,datetime);
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), "+f+F");
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), fu_flags);
tmpde=tmpde1 = FilesFind(files_find_mask, fuf_flags);
while (tmpde) {
while (tmpde)
{
TouchFile(tmpde->full_name, attr, cdt);
tmpde = tmpde->next;
}

View File

@ -2,7 +2,8 @@
I64 DirTreeSerializeSize(CDirEntry *tmpde)
{
I64 res = 0;
while (tmpde) {
while (tmpde)
{
res += CDIR_SIZE + 1;
if (tmpde->attr & RS_ATTR_DIR)
res += DirTreeSerializeSize(tmpde->sub);
@ -13,13 +14,15 @@ I64 DirTreeSerializeSize(CDirEntry *tmpde)
I64 DirTreeSerializeFill(CDirEntry *tmpde, U8 *dst)
{
I64 res = 0, i;
while (tmpde) {
while (tmpde)
{
*dst++ = 1;
res++;
MemCopy(dst, &tmpde->start, CDIR_SIZE);
dst += CDIR_SIZE;
res += CDIR_SIZE;
if (tmpde->attr & RS_ATTR_DIR) {
if (tmpde->attr & RS_ATTR_DIR)
{
i = DirTreeSerializeFill(tmpde->sub, dst);
dst += i;
res += i;
@ -34,14 +37,16 @@ public U8 *DirTreeSerialize(CDirEntry *tmpde,I64 *_size=NULL)
I64 size = DirTreeSerializeSize(tmpde);
U8 *buf = MAlloc(size);
DirTreeSerializeFill(tmpde, buf);
if (_size) *_size=size;
if (_size)
*_size = size;
return buf;
}
U8 *DirTreeUnserialize2(U8 *src, CDirEntry **tmpde)
{
CDirEntry *tmpde1;
if (*src++) {
if (*src++)
{
tmpde1 = CAlloc(sizeof(CDirEntry));
*tmpde = tmpde1;
MemCopy(&tmpde1->start, src, CDIR_SIZE);
@ -49,7 +54,8 @@ U8 *DirTreeUnserialize2(U8 *src,CDirEntry **tmpde)
if (tmpde1->attr & RS_ATTR_DIR)
src = DirTreeUnserialize2(src, &tmpde1->sub);
src = DirTreeUnserialize2(src, &tmpde1->next);
} else
}
else
*tmpde = NULL;
return src;
}
@ -64,12 +70,16 @@ public CDirEntry *DirTreeUnserialize(U8 *src)
U0 FOFlatten(CDirEntry *tmpde, CDirEntry **a, I64 *i)
{
CDirEntry *tmpde1;
while (tmpde) {
while (tmpde)
{
tmpde1 = tmpde->next;
if (tmpde->attr&RS_ATTR_DIR) {
if (tmpde->attr & RS_ATTR_DIR)
{
FOFlatten(tmpde->sub, a, i);
DirEntryDel(tmpde);
} else {
}
else
{
a[*i] = tmpde;
*i = *i + 1;
}
@ -112,7 +122,8 @@ public I64 Size(U8 *files_find_mask="/*",U8 *fu_flags=NULL,I64 round_to=0)
public I64 FileCount(CDirEntry *tmpde)
{//Count of files in $LK,"CDirEntry",A="MN:CDirEntry"$ tree.
I64 count = 0;
while (tmpde) {
while (tmpde)
{
if (tmpde->attr & RS_ATTR_DIR)
count += FileCount(tmpde->sub);
else
@ -130,7 +141,8 @@ public I64 FF(U8 *files_find_mask,U8 *fu_flags=NULL)
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), "+r+f+F");
FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), fu_flags);
tmpde=tmpde1 = FilesFind(files_find_mask, fuf_flags);
while (tmpde) {
while (tmpde)
{
PutFileLink(tmpde->full_name);
'\n';
count++;