diff --git a/Zenith-latest-2020-05-23-21_51_58.iso b/Zenith-latest-2020-06-02-16_51_42.iso similarity index 99% rename from Zenith-latest-2020-05-23-21_51_58.iso rename to Zenith-latest-2020-06-02-16_51_42.iso index d236efcd..61833390 100755 Binary files a/Zenith-latest-2020-05-23-21_51_58.iso and b/Zenith-latest-2020-06-02-16_51_42.iso differ diff --git a/src/Home/FilesRefactored.DD b/src/Home/FilesRefactored.DD index aabe46c6..80602b9e 100755 --- a/src/Home/FilesRefactored.DD +++ b/src/Home/FilesRefactored.DD @@ -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/ diff --git a/src/Zenith/ZBlkDev/DiskCheck.CC b/src/Zenith/ZBlkDev/DiskCheck.CC index 31054cad..c1fbbf54 100755 --- a/src/Zenith/ZBlkDev/DiskCheck.CC +++ b/src/Zenith/ZBlkDev/DiskCheck.CC @@ -1,97 +1,103 @@ #help_index "Info;File/Cmd Line (Typically);Cmd Line (Typically)" -Bool CheckDiskConfirm(Bool *_fix,Bool *_confirm) +Bool CheckDiskConfirm(Bool *_fix, Bool *_confirm) { - if (*_fix && *_confirm) { + if (*_fix && *_confirm) + { "Fix "; if (!YorN) - *_fix=FALSE; - *_confirm=FALSE; + *_fix = FALSE; + *_confirm = FALSE; } 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) { - tmpde2=tmpde1->next; + I64 i, j, errs = 0; + 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;iclus-drive->data_area>size) { - PrintErr("Invalid Clus:%s Clus:%X\n",tmpde1->full_name, - i+tmpde1->clus); + 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); 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++; } } DirEntryDel(tmpde1); - tmpde1=tmpde2; + tmpde1 = tmpde2; } return errs; } -I64 RedSeaCheckDisk(U8 drv_let,Bool *_fix,Bool *_confirm) +I64 RedSeaCheckDisk(U8 drv_let, Bool *_fix, Bool *_confirm) { - I64 i,j,bpc,size,errs=0; - CDrive *drive=Letter2Drive(drv_let),*old_dv=Fs->cur_dv; - U8 *files_find_mask=MStrPrint("%c:/*",Drive2Letter(drive)), - *old_dir=StrNew(Fs->cur_dir), - *bits,*bits2; + I64 i, j, bpc, size, errs = 0; + CDrive *drive = Letter2Drive(drv_let), *old_dv = Fs->cur_dv; + U8 *files_find_mask = MStrPrint("%c:/*", Drive2Letter(drive)), + *old_dir = StrNew(Fs->cur_dir), + *bits, *bits2; CDirEntry *ptr,*ptr2; Drive(drv_let); "Scanning...\n"; - size=(drive->size-(drive->data_area-drive->drv_offset))/drive->spc; - bpc=drive->spc<>3); - bits2=CAlloc((size+7)>>3+BLK_SIZE); - BlkRead(drive,bits2,drive->fat1,((size+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS); + size = (drive->size - (drive->data_area - drive->drv_offset)) / drive->spc; + bpc = drive->spc << BLK_SIZE_BITS; + bits = CAlloc((size + 7) >> 3); + bits2 = CAlloc((size + 7) >> 3 + BLK_SIZE); + BlkRead(drive, bits2, drive->fat1, ((size + 7) >> 3 + BLK_SIZE - 1) >> BLK_SIZE_BITS); //Get Root Dir size - ptr2=MAlloc(bpc); - BlkRead(drive,ptr2,drive->root_clus,1); - ptr=ptr2(U8 *)-offset(CDirEntry.start); - j=(ptr->size+bpc-1)/bpc; + ptr2 = MAlloc(bpc); + BlkRead(drive, ptr2, drive->root_clus, 1); + ptr = ptr2(U8 *) - offset(CDirEntry.start); + j = (ptr->size + bpc - 1) / bpc; Free(ptr2); - for (i=0;iroot_clus-drive->data_area>size) { - PrintErr("Invalid Clus: RootDir Clus:%X\n",i+drive->root_clus); + 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)) { - PrintErr("Dbl Alloc: RootDir Clus:%X\n",i+drive->root_clus); + 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)) { - PrintErr("UnAlloc: RootDir Clus:%X\n",i+drive->root_clus); + 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); - for (i=1;idata_area); + errs += RedSeaCheckDiskList(drive, FilesFind(files_find_mask, FUF_RECURSE), bits, bits2, size, bpc); + for (i = 1; i < size; i++) + if (Bt(bits2, i)) + { + PrintWarn("Shouldn't Alloc Clus:%0X\n", i + drive->data_area); errs++; - if (CheckDiskConfirm(_fix,_confirm)) - RedSeaFreeClus(drive,i+drive->data_area,1); + if (CheckDiskConfirm(_fix, _confirm)) + RedSeaFreeClus(drive, i + drive->data_area, 1); } Free(files_find_mask); @@ -103,97 +109,110 @@ 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) { - tmpde2=tmpde1->next; + I64 i, c, errs = 0; + 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 (0size) { - PrintErr("Invalid Clus:%s Clus:%X\n",tmpde1->full_name,c); + errs += FAT32CheckDiskList(drive, tmpde1->sub, bits, bits2, size, bpc); + i = 0; + c = tmpde1->clus; + while (0 < c < 0x0FFFFFF8) + { + if (c > size) + { + PrintErr("Invalid Clus:%s Clus:%X\n", tmpde1->full_name, c); errs++; break; } - if (LBts(bits,c)) { - PrintErr("Dbl Alloc:%s Clus:%X\n",tmpde1->full_name,c); + if (LBts(bits, c)) + { + PrintErr("Dbl Alloc:%s Clus:%X\n", tmpde1->full_name, c); errs++; } - if (!bits2[c]) { - PrintErr("UnAlloc:%s Clus:%X\n",tmpde1->full_name,c); + if (!bits2[c]) + { + PrintErr("UnAlloc:%s Clus:%X\n", tmpde1->full_name, c); errs++; - } else - bits2[c]=0; - c=ClusNumNext(drive,c); + } + else + bits2[c] = 0; + c = ClusNumNext(drive, c); i++; } - if (!(tmpde1->attr & RS_ATTR_DIR)) { - i*=bpc; - if (tmpde1->size>i) { - PrintErr("Alloced File Too Short:%s\n",tmpde1->full_name); + if (!(tmpde1->attr & RS_ATTR_DIR)) + { + i *= bpc; + if (tmpde1->size>i) + { + PrintErr("Alloced File Too Short:%s\n", tmpde1->full_name); errs++; } - if (i>tmpde1->size+bpc-1) { - PrintWarn("Alloced File Too Long:%s\n",tmpde1->full_name); + if (i > tmpde1->size + bpc - 1) + { + PrintWarn("Alloced File Too Long:%s\n", tmpde1->full_name); errs++; } } DirEntryDel(tmpde1); - tmpde1=tmpde2; + tmpde1 = tmpde2; } return errs; } -I64 FAT32CheckDisk(U8 drv_let,Bool *_fix,Bool *_confirm) +I64 FAT32CheckDisk(U8 drv_let, Bool *_fix, Bool *_confirm) { - I64 i,bpc,size,c,errs=0; - CDrive *drive=Letter2Drive(drv_let),*old_dv=Fs->cur_dv; - U8 *files_find_mask=MStrPrint("%c:/*",Drive2Letter(drive)), - *old_dir=StrNew(Fs->cur_dir), - *bits; + I64 i, bpc, size, c, errs = 0; + CDrive *drive = Letter2Drive(drv_let), *old_dv = Fs->cur_dv; + U8 *files_find_mask = MStrPrint("%c:/*", Drive2Letter(drive)), + *old_dir = StrNew(Fs->cur_dir), + *bits; U32 *bits2; Drive(drv_let); "Scanning...\n"; - size=(drive->size-(drive->data_area-drive->drv_offset))/drive->spc; - bpc=drive->spc<>3); - bits2=CAlloc(size*4+BLK_SIZE); - BlkRead(drive,bits2,drive->fat1,(size*4+BLK_SIZE-1)>>BLK_SIZE_BITS); + size = (drive->size - (drive->data_area - drive->drv_offset)) / drive->spc; + bpc = drive->spc << BLK_SIZE_BITS; + bits = CAlloc((size + 7) >> 3); + bits2 = CAlloc(size * 4 + BLK_SIZE); + BlkRead(drive, bits2, drive->fat1, (size * 4 + BLK_SIZE - 1) >> BLK_SIZE_BITS); - c=drive->root_clus; - while (0size) { - PrintErr("Invalid Clus: RootDir Clus:%X\n",c); + c = drive->root_clus; + while (0 < c < 0x0FFFFFF8) + { + if (c > size) + { + PrintErr("Invalid Clus: RootDir Clus:%X\n", c); errs++; break; } - if (LBts(bits,c)) { - PrintErr("Dbl Alloc: RootDir Clus:%X\n",c); + if (LBts(bits, c)) + { + PrintErr("Dbl Alloc: RootDir Clus:%X\n", c); errs++; } - if (!bits2[c]) { - PrintErr("UnAlloc: RootDir Clus:%X\n",c); + if (!bits2[c]) + { + PrintErr("UnAlloc: RootDir Clus:%X\n", c); errs++; - } else - bits2[c]=0; - c=ClusNumNext(drive,c); + } + 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;ifs_type) { + I64 errs = 0; + CDrive *drive = Letter2Drive(drv_let); + switch (drive->fs_type) + { case FSt_REDSEA: - errs=RedSeaCheckDisk(drv_let,&fix,&confirm); + errs = RedSeaCheckDisk(drv_let, &fix, &confirm); break; case FSt_FAT32: - errs=FAT32CheckDisk(drv_let,&fix,&confirm); + errs = FAT32CheckDisk(drv_let, &fix, &confirm); break; 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, " - "reformat, and copy back. " - "Or, copy from a back-up.\n"; + "reformat, and copy back. " + "Or, copy from a back-up.\n"; } return errs; } 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), - s=drive->size+drive->drv_offset-drive->data_area; + CDrive *drive = Letter2Drive(drv_let); + 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; + CDC *dc = DCAlias; SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$ WinMax; @@ -243,27 +265,31 @@ U0 RedSeaDriveView(U8 drv_let=0) DocCursor; DocClear; DCFill; - try { - i=((s+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS; - bitmap=MAlloc(i<fat1,i); - i=0; - for (y=0;y> 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++) + { if (KeyScan) break; - for (x=0;xcolor=ROP_XOR+BLUE^TRANSPARENT; + for (x = 0; x < GR_WIDTH - FONT_WIDTH << 1; x++) + { + lohi = i * s; + c1 = lohi / l; + if (Bt(bitmap, c1)) + dc->color = ROP_XOR + BLUE ^ TRANSPARENT; else - dc->color=ROP_XOR+WHITE^TRANSPARENT; - GrPlot(dc,x,y); + dc->color = ROP_XOR + WHITE ^ TRANSPARENT; + GrPlot(dc, x, y); i++; } } Free(bitmap); - } catch + } + catch DriveUnlock(drive); CharGet; @@ -273,11 +299,12 @@ 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), - s=(drive->size+drive->spc-1)/drive->spc-(2+drive->data_area-drive->drv_offset); + CDrive *drive = Letter2Drive(drv_let); + 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; + CDC *dc = DCAlias; SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$ WinMax; @@ -285,27 +312,31 @@ U0 FAT32DriveView(U8 drv_let=0) DocCursor; DocClear; DCFill; - try { - i=(s*4+BLK_SIZE-1)>>BLK_SIZE_BITS; - bitmap=MAlloc(i<fat1,i); - i=0; - for (y=0;y> 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++) + { if (KeyScan) break; - for (x=0;xcolor=ROP_XOR+BLUE^TRANSPARENT; + dc->color = ROP_XOR + BLUE ^ TRANSPARENT; else - dc->color=ROP_XOR+WHITE^TRANSPARENT; - GrPlot(dc,x,y); + dc->color = ROP_XOR + WHITE ^ TRANSPARENT; + GrPlot(dc, x, y); i++; } } Free(bitmap); - } catch + } + catch DriveUnlock(drive); CharGet; @@ -315,9 +346,10 @@ U0 FAT32DriveView(U8 drv_let=0) } 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; + 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; @@ -332,49 +364,51 @@ public U0 DriveView(U8 drv_let=0) public U0 DiskView(U8 drv_let=0) {//Disk view. Pie chart of partition sizes. - I64 i,j,attr, - h=Fs->pix_width, - v=Fs->pix_height, - radius; + I64 i, j, attr, + h = Fs->pix_width, + v = Fs->pix_height, + radius; CDrive *drive; - CBlkDev *bd=Letter2BlkDev(drv_let); - CDC *dc=DCAlias; - F64 sect_start,sect_end; + CBlkDev *bd = Letter2BlkDev(drv_let); + CDC *dc = DCAlias; + F64 sect_start, sect_end; SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$ DocCursor; DocClear; DCFill; - if (hcolor=BLACK; - GrCircle(dc,h>>1,v>>1,radius); + radius = 0.4 * v; + dc->color = BLACK; + GrCircle(dc, h >> 1, v >> 1, radius); - j=1; - for (i=0;ibd && 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)); + j = 1; + for (i = 0; i < DRIVES_NUM; i++) + { + drive = &blkdev.drvs[i]; + 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)); - 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"); - dc->color.c1=attr>>4; - dc->color|=ROPF_DITHER; + 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"); + dc->color.c1 = attr >> 4; + dc->color |= ROPF_DITHER; GrFloodFill(dc, - h>>1+(radius-4)*Cos((sect_start+sect_end)/2), - v>>1+(radius-4)*Sin((sect_start+sect_end)/2),FALSE); + h >> 1 + (radius - 4) * Cos((sect_start + sect_end) / 2), + v >> 1 + (radius - 4) * Sin((sect_start + sect_end) / 2), FALSE); j++; } } @@ -387,52 +421,57 @@ public U0 DiskView(U8 drv_let=0) I64 RedSeaUnusedDriveSpace(U8 drv_let=0) { - CDrive *drive=Letter2Drive(drv_let); - I64 res=0,i,l; + CDrive *drive = Letter2Drive(drv_let); + I64 res = 0, i, l; U8 *bitmap; - try { - l=drive->size+drive->drv_offset-drive->data_area; - i=((l+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS; - bitmap=MAlloc(i<fat1,i); - for (i=0;isize + drive->drv_offset - drive->data_area; + i = ((l + 7) >> 3 + BLK_SIZE - 1) >> BLK_SIZE_BITS; + bitmap = MAlloc(i << BLK_SIZE_BITS); + BlkRead(drive, bitmap, drive->fat1, i); + for (i = 0; i < l; i++) + if (!Bt(bitmap, i)) res++; Free(bitmap); - } catch + } + catch DriveUnlock(drive); - return res*BLK_SIZE*drive->spc; + return res * BLK_SIZE * drive->spc; } I64 FAT32UnusedDriveSpace(U8 drv_let=0) { - CDrive *drive=Letter2Drive(drv_let); - I64 res=0,i,l; + CDrive *drive = Letter2Drive(drv_let); + I64 res = 0, i, l; U32 *bitmap; - 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<fat1,i); - for (i=0;isize + 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); + BlkRead(drive, bitmap, drive->fat1, i); + for (i = 0; i < l; i++) if (!bitmap[i]) res++; Free(bitmap); - } catch + } + catch DriveUnlock(drive); - return res*BLK_SIZE*drive->spc; + return res * BLK_SIZE * drive->spc; } public I64 DriveUnused(U8 drv_let=0) {//Returns unused size in bytes. - CDrive *drive=Letter2Drive(drv_let),*old_dv=Fs->cur_dv; - U8 *old_dir=StrNew(Fs->cur_dir); - I64 res=0; + CDrive *drive = Letter2Drive(drv_let), *old_dv = Fs->cur_dv; + 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); + res = RedSeaUnusedDriveSpace(drv_let); break; case FSt_FAT32: - res=FAT32UnusedDriveSpace(drv_let); + res = FAT32UnusedDriveSpace(drv_let); break; default: PrintErr("File System Not Supported\n"); diff --git a/src/Zenith/ZBlkDev/DiskPart.CC b/src/Zenith/ZBlkDev/DiskPart.CC index 29f2d9e4..e9c73a8d 100755 --- a/src/Zenith/ZBlkDev/DiskPart.CC +++ b/src/Zenith/ZBlkDev/DiskPart.CC @@ -1,16 +1,16 @@ #help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically)" -#define ROUND_DRIVE_TO (63*255) -#define DRIVE_HEADER 63 +#define ROUND_DRIVE_TO (63 * 255) +#define DRIVE_HEADER 63 class CPlannedDrive { - CPlannedDrive *next,*last; + CPlannedDrive *next, *last; I64 size; Bool pri; }; -public I64 DiskPart(U8 drv_let=0,...) +public I64 DiskPart(U8 drv_let=0, ...) {/*Partition the disk containing partition drv_let. drv_let=0 means add new drive that is not already mounted. @@ -19,147 +19,158 @@ drv_let=0 means add new drive that is not already mounted. */ CBlkDev *bd; - CPlannedDrive head,*tmppp; + 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; + Bool pri = TRUE; + 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" - "operating system's partitioner.\n" - "If you use this, it may, in fact,\n" - "make your hard drive impossible\n" - "to repartition with other operating\n" - "until you set block zero to zero\n" - "with $$LK,\"BootMHDZero\",\"MN:BootMHDZero\"$$()\n\n\n" - "Continue"; - if (argc<=cur_arg && !YorN) + "with other operating systems.\n" + "You really should use another\n" + "operating system's partitioner.\n" + "If you use this, it may, in fact,\n" + "make your hard drive impossible\n" + "to repartition with other operating\n" + "until you set block zero to zero\n" + "with $$LK,\"BootMHDZero\",\"MN:BootMHDZero\"$$()\n\n\n" + "Continue"; + if (argc <= cur_arg && !YorN) return 0; '\n'; - 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 && !Letter2BlkDev(drv_let, FALSE)) + drv_let = 0; + if (!drv_let && !(drv_let = Mount(TRUE)) || !(bd = Letter2BlkDev(drv_let, FALSE)) || bd->type != BDT_ATA) return 0; - total=bd->max_blk+1; + 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) { - tmppp=MAlloc(sizeof(CPlannedDrive)); - do { - "$$RED$$Partition %C$$FG$$\n",drv_let2; - tmppp->pri=FALSE; - if (pri) { + drv_let2 = bd->first_drive_let; + remaining = FloorU64(bd->max_blk + 1, ROUND_DRIVE_TO); + while (FloorU64(remaining, ROUND_DRIVE_TO) >= ROUND_DRIVE_TO) + { + tmppp = MAlloc(sizeof(CPlannedDrive)); + do + { + "$$RED$$Partition %C$$FG$$\n", drv_let2; + tmppp->pri = FALSE; + 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 - pri=FALSE; + tmppp->pri = TRUE; + if (pri_count == 3) + pri = FALSE; + } + else + pri = FALSE; } - "\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)); + "\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))); - QueueInsert(tmppp,head.last); - remaining-=tmppp->size; + 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++; } "\n\n!!! Repartition Drive !!!\n\n"; - tmppp=head.next; - drv_let2=bd->first_drive_let; - while (tmppp!=&head) { - "Drive %C:%08X ",drv_let2,tmppp->size; + tmppp = head.next; + drv_let2 = bd->first_drive_let; + while (tmppp != &head) + { + "Drive %C:%08X ", drv_let2, tmppp->size; if (tmppp->pri) "Primary\n"; else "Logical\n"; - tmppp=tmppp->next; + tmppp = tmppp->next; drv_let2++; } if (!argc && !AreYouSure) goto pd_done; - remaining=FloorU64(bd->max_blk+1,ROUND_DRIVE_TO)-ROUND_DRIVE_TO; - tmppp=head.next; - MemSet(&mbr,0,BLK_SIZE); - mbr.signature=0xAA55; - offset=0; - for (i=0;isize-DRIVE_HEADER; - offset+=tmppp->size; - remaining-=tmppp->size; - tmppp=tmppp->next; + remaining = FloorU64(bd->max_blk + 1, ROUND_DRIVE_TO) - ROUND_DRIVE_TO; + tmppp = head.next; + MemSet(&mbr, 0, BLK_SIZE); + mbr.signature = 0xAA55; + offset = 0; + for (i = 0; i < pri_count; i++) + { + mbr.p[i].active = 0x80; + mbr.p[i].start_head = 0; + mbr.p[i].start_cyl = 0x101; + mbr.p[i].type = 1; //Will get set different. + mbr.p[i].end_head = 0xFE; + mbr.p[i].end_cyl = 0xFFFF; + mbr.p[i].offset = DRIVE_HEADER + offset; + mbr.p[i].size = tmppp->size - DRIVE_HEADER; + offset += tmppp->size; + remaining -= tmppp->size; + tmppp = tmppp->next; } - if (!i) i++; - if (tmppp!=&head) { - mbr.p[i].active=0x80; - mbr.p[i].start_head=0; - mbr.p[i].start_cyl=0x101; - mbr.p[i].type=0xF; - mbr.p[i].end_head=0xFE; - mbr.p[i].end_cyl=0xFFFF; - mbr.p[i].offset=offset; - mbr.p[i].size=remaining; - ext_base=offset; + if (!i) + i++; + if (tmppp != &head) + { + mbr.p[i].active = 0x80; + mbr.p[i].start_head = 0; + mbr.p[i].start_cyl = 0x101; + mbr.p[i].type = 0xF; + mbr.p[i].end_head = 0xFE; + mbr.p[i].end_cyl = 0xFFFF; + mbr.p[i].offset = offset; + mbr.p[i].size = remaining; + ext_base = offset; } - ATAWriteBlks(bd,&mbr,0,1); + ATAWriteBlks(bd, &mbr, 0, 1); - while (tmppp!=&head) { - start_offset=offset; - MemSet(&mbr,0,BLK_SIZE); - mbr.signature=0xAA55; + while (tmppp != &head) + { + start_offset = offset; + MemSet(&mbr, 0, BLK_SIZE); + mbr.signature = 0xAA55; - mbr.p[0].active=0x80; - mbr.p[0].start_head=1; - mbr.p[0].start_cyl=0x101; - mbr.p[0].type=1; //Will get set different. - mbr.p[0].end_head=0xFE; - mbr.p[0].end_cyl=0xFFFF; - mbr.p[0].offset=DRIVE_HEADER; - mbr.p[0].size=tmppp->size-DRIVE_HEADER; - offset+=tmppp->size; - tmppp=tmppp->next; - if (tmppp!=&head) { - mbr.p[1].active=0x80; - mbr.p[1].start_head=0; - mbr.p[1].start_cyl=0x101; - mbr.p[1].type=5; - mbr.p[1].end_head=0xFE; - mbr.p[1].end_cyl=0xFFFF; - mbr.p[1].offset=offset-ext_base; - mbr.p[1].size=tmppp->size; + mbr.p[0].active = 0x80; + mbr.p[0].start_head = 1; + mbr.p[0].start_cyl = 0x101; + mbr.p[0].type = 1; //Will get set different. + mbr.p[0].end_head = 0xFE; + mbr.p[0].end_cyl = 0xFFFF; + mbr.p[0].offset = DRIVE_HEADER; + mbr.p[0].size = tmppp->size - DRIVE_HEADER; + offset += tmppp->size; + tmppp = tmppp->next; + if (tmppp != &head) + { + mbr.p[1].active = 0x80; + mbr.p[1].start_head = 0; + mbr.p[1].start_cyl = 0x101; + mbr.p[1].type = 5; + mbr.p[1].end_head = 0xFE; + mbr.p[1].end_cyl = 0xFFFF; + mbr.p[1].offset = offset - ext_base; + mbr.p[1].size = tmppp->size; } - ATAWriteBlks(bd,&mbr,start_offset,1); + ATAWriteBlks(bd, &mbr, start_offset, 1); } - bd->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS); - BlkDevAdd(bd,,FALSE,TRUE); - for (i=bd->first_drive_let;iflags &= ~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS); + BlkDevAdd(bd,, FALSE, TRUE); + for (i = bd->first_drive_let; i < drv_let2; i++) + Format(i,, FALSE); pd_done: - while (head.next!=&head) { - tmppp=head.next; + while (head.next != &head) + { + tmppp = head.next; QueueRemove(tmppp); Free(tmppp); } diff --git a/src/Zenith/ZBlkDev/FileMgr.CC b/src/Zenith/ZBlkDev/FileMgr.CC index ed19639d..3e9dcc61 100755 --- a/src/Zenith/ZBlkDev/FileMgr.CC +++ b/src/Zenith/ZBlkDev/FileMgr.CC @@ -1,18 +1,22 @@ #help_index "DolDoc/Output;StdOut/DolDoc" -U0 DirFileDoc(CDoc *doc,CDirEntry *tmpde) +U0 DirFileDoc(CDoc *doc, CDirEntry *tmpde) { - 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$$"); + 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 { - tmpde->user_data=DocPrint(doc,"$$MU,\"%s\",U=0x%X$$",tmpde->name,tmpde); - DocPrint(doc,"\n"); + DirFileDoc(doc, tmpde->sub); + DocPrint(doc, "$$ID,-2$$"); } - tmpde=tmpde->next; + else + { + tmpde->user_data = DocPrint(doc, "$$MU,\"%s\",U=0x%X$$", tmpde->name, tmpde); + DocPrint(doc, "\n"); + } + tmpde = tmpde->next; } } @@ -30,243 +34,283 @@ class CFMUncollapsedList CFMUncollapsedList *FMCollectUncollapsedList(CDoc *doc) { - CDocEntry *doc_e=doc->head.next; - CFMUncollapsedList *res=NULL,*tmpc; + 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) { - tmpc=MAlloc(sizeof(CFMUncollapsedList)); - tmpc->next=res; - res=tmpc; - tmpc->name=StrNew(tmpde->full_name); + 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; + tmpc->name = StrNew(tmpde->full_name); } } } - doc_e=doc_e->next; + doc_e = doc_e->next; } 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; + CDocEntry *doc_e = doc->head.next; CFMUncollapsedList *tmpc1; CDirEntry *tmpde; - 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)) { - doc_e->de_flags&=~DOCEF_CHECKED_COLLAPSED; + 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)) + { + doc_e->de_flags &= ~DOCEF_CHECKED_COLLAPSED; break; } - tmpc1=tmpc1->next; + tmpc1 = tmpc1->next; } - 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))) { - doc->cur_entry=doc_e; - if (StrLen(tmpde->full_name)==StrLen(next_entry)) - cur_entry=NULL; - } + 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 (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))) { - 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))) { - doc->cur_entry=doc_e; - if (StrLen(tmpde->full_name)==StrLen(next_entry)) - cur_entry=NULL; + 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; } } } } - doc_e=doc_e->next; + 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))) + { + 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))) + { + doc->cur_entry = doc_e; + if (StrLen(tmpde->full_name) == StrLen(next_entry)) + cur_entry = NULL; + } + } + } + } + doc_e = doc_e->next; } } U0 FMDelUncollapsedList(CFMUncollapsedList *tmpc) { CFMUncollapsedList *tmpc1; - while (tmpc) { - tmpc1=tmpc->next; + while (tmpc) + { + tmpc1 = tmpc->next; Free(tmpc->name); Free(tmpc); - tmpc=tmpc1; + tmpc = tmpc1; } } -CDirEntry *FMRebuildDocDrive(U8 drv_let,CDoc *doc,CDirEntry **_head,Bool init) +CDirEntry *FMRebuildDocDrive(U8 drv_let, CDoc *doc, CDirEntry **_head, Bool init) { - CDirEntry *tmpde,*tmpde1; + CDirEntry *tmpde, *tmpde1; U8 *st; - tmpde=CAlloc(sizeof(CDirEntry)); - tmpde->full_name=MStrPrint("%C:/",drv_let); - tmpde->attr=RS_ATTR_DIR; - st=MStrPrint("%c:/*",drv_let); + tmpde = CAlloc(sizeof(CDirEntry)); + tmpde->full_name = MStrPrint("%C:/", drv_let); + tmpde->attr = RS_ATTR_DIR; + st = MStrPrint("%c:/*", drv_let); if (init) - tmpde->sub=tmpde1=FilesFind(st,FUF_RECURSE); + tmpde->sub = tmpde1 = FilesFind(st, FUF_RECURSE); else - tmpde1=NULL; + tmpde1 = NULL; Free(st); - tmpde->user_data=DocPrint(doc,"$$TR,\"%s\",U=0x%X$$",tmpde->full_name,tmpde); - tmpde->next=*_head; - *_head=tmpde; - DocPrint(doc,"\n$$ID,+2$$"); + tmpde->user_data = DocPrint(doc, "$$TR,\"%s\",U=0x%X$$", tmpde->full_name, tmpde); + tmpde->next = *_head; + *_head = tmpde; + DocPrint(doc, "\n$$ID,+2$$"); DocBottom(doc); - if (init) { - DirFileDoc(doc,tmpde1); - while (tmpde1) { - tmpde1->parent=tmpde; - tmpde1=tmpde1->next; + if (init) + { + DirFileDoc(doc, tmpde1); + while (tmpde1) + { + tmpde1->parent = tmpde; + tmpde1 = tmpde1->next; } } - DocPrint(doc,"$$ID,-2$$"); + DocPrint(doc, "$$ID,-2$$"); return tmpde; } #define DEF2_PROCESSED 1 #define DEF2_NOT_INITIALIZED 2 -U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode) +U0 FMRebuildDoc(CDoc **_doc, CDirEntry **_head, I64 mode) { CDrive *drive; I64 i; - CDoc *doc=*_doc,*doc2=sys_clip_doc,*parent_doc; - CFMUncollapsedList *tmpc=NULL; - U8 *cur_entry=NULL,*next_entry=NULL; + CDoc *doc = *_doc, *doc2 = sys_clip_doc, *parent_doc; + CFMUncollapsedList *tmpc = NULL; + U8 *cur_entry = NULL, *next_entry = NULL; CDocEntry *doc_ce; - CDirEntry *tmpde,*tmpde1,*cur_tree_entry; + CDirEntry *tmpde, *tmpde1, *cur_tree_entry; if (!doc) - parent_doc=DocPut; - else { - parent_doc=doc->parent_doc; - Fs->put_doc=Fs->display_doc=NULL; + parent_doc = DocPut; + else + { + parent_doc = doc->parent_doc; + Fs->put_doc = Fs->display_doc = NULL; DocUnlock(doc); Refresh; DocLock(doc); - cur_tree_entry=NULL; - doc_ce=doc->cur_entry; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - cur_tree_entry=doc_ce->user_data; + cur_tree_entry = NULL; + doc_ce = doc->cur_entry; + if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL) + cur_tree_entry = doc_ce->user_data; if (cur_tree_entry) - cur_entry=StrNew(cur_tree_entry->full_name); - tmpde=NULL; - if (doc_ce!=doc) - doc_ce=doc_ce->next; - while (doc_ce!=doc) { - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + cur_entry = StrNew(cur_tree_entry->full_name); + tmpde = NULL; + if (doc_ce != doc) + doc_ce = doc_ce->next; + 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) { - tmpde1=tmpde->parent; - while (tmpde1) { - if (tmpde1==cur_tree_entry) { - tmpde=NULL; + tmpde = NULL; + if (tmpde) + { + tmpde1 = tmpde->parent; + while (tmpde1) + { + if (tmpde1 == cur_tree_entry) + { + tmpde = NULL; break; - } else - tmpde1=tmpde1->parent; + } + else + tmpde1 = tmpde1->parent; } if (tmpde) break; } - doc_ce=doc_ce->next; + doc_ce = doc_ce->next; } if (tmpde) - next_entry=StrNew(tmpde->full_name); + next_entry = StrNew(tmpde->full_name); - tmpc=FMCollectUncollapsedList(doc); + tmpc = FMCollectUncollapsedList(doc); DocDel(doc); } - if (*_head) { + if (*_head) + { DirTreeDel(*_head); - *_head=NULL; + *_head = NULL; } - doc=DocNew; - doc->desc='FileMan'; - doc->parent_doc=parent_doc; - doc->flags|=DOCF_FORM; - switch (mode) { + doc = DocNew; + doc->desc = 'FileMan'; + doc->parent_doc = parent_doc; + doc->flags |= DOCF_FORM; + switch (mode) + { case FM_NORMAL: DocPrint(doc,"$$PURPLE$$File Manager\n\n" "$$LK,\"Click for Help\",A=\"FI:::/Doc/FileMgr.DD\"$$\n\n"); break; case FM_PICK_FILE: - DocPrint(doc,"$$PURPLE$$Pick file and press \n\n"); - doc->flags|=DOCF_SIZE_MIN; + DocPrint(doc, "$$PURPLE$$Pick file and press \n\n"); + doc->flags |= DOCF_SIZE_MIN; break; case FM_PICK_DIR: - DocPrint(doc,"$$PURPLE$$Pick directory and press \n\n"); - doc->flags|=DOCF_SIZE_MIN; + DocPrint(doc, "$$PURPLE$$Pick directory and press \n\n"); + doc->flags |= DOCF_SIZE_MIN; break; } - DocPrint(doc,"$$LTBLUE$$"); - for (i=0;ibd->type==BDT_ATAPI) { - if (drive->bd->flags&BDF_INITIALIZED) - tmpde=FMRebuildDocDrive(Drive2Letter(drive),doc,_head,TRUE); - else { - tmpde=FMRebuildDocDrive(Drive2Letter(drive),doc,_head,FALSE); - tmpde->user_data2|=DEF2_NOT_INITIALIZED; + DocPrint(doc, "$$LTBLUE$$"); + for (i = 0; i < DRIVES_NUM; i++) + { + drive = &blkdev.drvs[i]; + if (drive->bd->type == BDT_ATAPI) + { + if (drive->bd->flags & BDF_INITIALIZED) + tmpde = FMRebuildDocDrive(Drive2Letter(drive), doc, _head, TRUE); + 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) - FMRebuildDocDrive(Drive2Letter(drive),doc,_head,TRUE); + } + else if (drive->fs_type == FSt_REDSEA || drive->fs_type == FSt_FAT32) + FMRebuildDocDrive(Drive2Letter(drive), doc, _head, TRUE); } DocTop(doc); - FMMarkUncollapsed(doc,tmpc,cur_entry,next_entry); + FMMarkUncollapsed(doc, tmpc, cur_entry, next_entry); DocCenter(doc); - DocReset(doc2,TRUE); + DocReset(doc2, TRUE); FMDelUncollapsedList(tmpc); Free(cur_entry); Free(next_entry); - *_doc=doc; + *_doc = doc; DocLock(doc); - Fs->put_doc=Fs->display_doc=doc; + Fs->put_doc = Fs->display_doc=doc; } U0 FMRename(CDoc *doc) { CEdFileName fn; - CDocEntry *doc_e=doc->cur_entry; - CDirEntry *tmpde=NULL,*parent; - if (doc_e->type_u8==DOCT_MENU_VAL) { - tmpde=doc_e->user_data; - if (parent=tmpde->parent) { + CDocEntry *doc_e = doc->cur_entry; + CDirEntry *tmpde = NULL, *parent; + if (doc_e->type_u8 == DOCT_MENU_VAL) + { + tmpde = doc_e->user_data; + if (parent = tmpde->parent) + { Cd(parent->full_name); - StrCopy(fn.name,tmpde->name); - if (DocForm(&fn)) { + StrCopy(fn.name, tmpde->name); + if (DocForm(&fn)) + { Silent; - Move(tmpde->name,fn.name); + Move(tmpde->name, fn.name); Silent(OFF); } } - } else if (doc_e->type_u8==DOCT_TREE) { - tmpde=doc_e->user_data; - if (parent=tmpde->parent) { + } + else if (doc_e->type_u8 == DOCT_TREE) + { + tmpde = doc_e->user_data; + if (parent = tmpde->parent) + { Cd(parent->full_name); - StrCopy(fn.name,tmpde->name); - if (DocForm(&fn)) { - if (StrCompare(tmpde->name,fn.name)) { + StrCopy(fn.name, tmpde->name); + if (DocForm(&fn)) + { + if (StrCompare(tmpde->name, fn.name)) + { Silent; - if (CopyTree(tmpde->name,fn.name)) + if (CopyTree(tmpde->name, fn.name)) DelTree(tmpde->name); Silent(OFF); } @@ -278,23 +322,29 @@ U0 FMRename(CDoc *doc) U0 FMMkDir(CDoc *doc) { CEdFileName fn; - CDocEntry *doc_e=doc->cur_entry; - CDirEntry *tmpde=NULL,*parent; - *fn.name=0; - if (doc_e->type_u8==DOCT_MENU_VAL) { - tmpde=doc_e->user_data; - if (parent=tmpde->parent) { + CDocEntry *doc_e = doc->cur_entry; + CDirEntry *tmpde = NULL, *parent; + *fn.name = 0; + if (doc_e->type_u8 == DOCT_MENU_VAL) + { + tmpde = doc_e->user_data; + 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) { - tmpde=doc_e->user_data; + } + 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); @@ -305,20 +355,23 @@ U0 FMMkDir(CDoc *doc) U0 FMDelete(CDoc *doc) { U8 *st; - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - if (doc_ce->type_u8==DOCT_MENU_VAL) { - tmpde=doc_ce->user_data; + if (doc_ce->type_u8 == DOCT_MENU_VAL) + { + tmpde = doc_ce->user_data; Silent; - st=MStrPrint("Delete: %s",tmpde->full_name); + st = MStrPrint("Delete: %s", tmpde->full_name); if (PopUpCancelOk(st)) Del(tmpde->full_name); Free(st); Silent(OFF); - } else if (doc_ce->type_u8==DOCT_TREE) { - tmpde=doc_ce->user_data; + } + else if (doc_ce->type_u8 == DOCT_TREE) + { + tmpde = doc_ce->user_data; Silent; - st=MStrPrint("Delete: %s",tmpde->full_name); + st = MStrPrint("Delete: %s", tmpde->full_name); if (PopUpCancelOk(st)) DelTree(tmpde->full_name); Free(st); @@ -328,15 +381,16 @@ U0 FMDelete(CDoc *doc) U0 FMChangeDisk(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL) + tmpde = doc_ce->user_data; else - tmpde=NULL; - if (tmpde) { + tmpde = NULL; + if (tmpde) + { while (tmpde->parent) - tmpde=tmpde->parent; + tmpde = tmpde->parent; Silent; DiskChange(*tmpde->full_name); Silent(OFF); @@ -345,46 +399,49 @@ U0 FMChangeDisk(CDoc *doc) U0 FMMountISO(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - if (doc_ce->type_u8==DOCT_MENU_VAL && (tmpde=doc_ce->user_data)) + if (doc_ce->type_u8 == DOCT_MENU_VAL && (tmpde = doc_ce->user_data)) MountFile(tmpde->full_name); } U0 FMUnmount(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; I64 drv_let; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL) + tmpde = doc_ce->user_data; else - tmpde=NULL; - if (tmpde) { + tmpde = NULL; + if (tmpde) + { while (tmpde->parent) - tmpde=tmpde->parent; - drv_let=*tmpde->full_name; - if (Letter2BlkDev(drv_let)!=Letter2BlkDev(':')) + tmpde = tmpde->parent; + drv_let = *tmpde->full_name; + if (Letter2BlkDev(drv_let) != Letter2BlkDev(':')) Unmount(drv_let); } } U0 FMFormatDrive(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - U8 *st=NULL; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + U8 *st = NULL; + if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL) + tmpde = doc_ce->user_data; else - tmpde=NULL; - if (tmpde) { + tmpde = NULL; + if (tmpde) + { while (tmpde->parent) - tmpde=tmpde->parent; - st=MStrPrint("Format Drive '%c'?\nAre You Sure?\n",*tmpde->full_name); - if (PopUpCancelOk(st)) { + tmpde = tmpde->parent; + st = MStrPrint("Format Drive '%c'?\nAre You Sure?\n", *tmpde->full_name); + if (PopUpCancelOk(st)) + { Silent; - Format(*tmpde->full_name,,FALSE); + Format(*tmpde->full_name,, FALSE); Silent(OFF); } } @@ -393,18 +450,20 @@ U0 FMFormatDrive(CDoc *doc) U0 FMMakeISO(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + 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 (doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=tmpde->parent; - if (tmpde && *tmpde->full_name) { + tmpde = NULL; + if (tmpde) + { + if (doc_ce->type_u8 == DOCT_MENU_VAL) + tmpde = tmpde->parent; + if (tmpde && *tmpde->full_name) + { Silent; - RedSeaISO(,tmpde->full_name); + RedSeaISO(, tmpde->full_name); Silent(OFF); } } @@ -412,15 +471,16 @@ U0 FMMakeISO(CDoc *doc) U0 FMBurnISO(CDoc *doc) { - CDocEntry *doc_ce=doc->cur_entry; + CDocEntry *doc_ce = doc->cur_entry; CDirEntry *tmpde; - if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL) - tmpde=doc_ce->user_data; + if (doc_ce->type_u8 == DOCT_TREE || doc_ce->type_u8 == DOCT_MENU_VAL) + tmpde = doc_ce->user_data; else - tmpde=NULL; - if (tmpde) { + tmpde = NULL; + if (tmpde) + { while (tmpde->parent) - tmpde=tmpde->parent; + tmpde = tmpde->parent; Silent; DVDImageWrite(*tmpde->full_name); Silent(OFF); @@ -429,45 +489,52 @@ U0 FMBurnISO(CDoc *doc) U0 FMCopy(CDoc *doc) { - CDoc *doc2=sys_clip_doc; + CDoc *doc2 = sys_clip_doc; U8 *st; - CDocEntry *doc_ce=doc->cur_entry,*doc_e; - CDirEntry *tmpde,*tmpde1=NULL,*tmpde2; - Bool unlock_doc2=DocLock(doc2); - doc_e=doc2->head.next; + CDocEntry *doc_ce = doc->cur_entry, *doc_e; + CDirEntry *tmpde, *tmpde1 = NULL, *tmpde2; + Bool unlock_doc2 = DocLock(doc2); + doc_e = doc2->head.next; - tmpde1=doc_ce->user_data; - if (doc_ce->type_u8==DOCT_MENU_VAL) - 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) { - tmpde=doc_e->user_data; - tmpde->user_data2|=DEF2_PROCESSED; - tmpde2=tmpde->parent; - if (!tmpde2 || !(tmpde2->user_data2&DEF2_PROCESSED)) { + tmpde1 = doc_ce->user_data; + if (doc_ce->type_u8 == DOCT_MENU_VAL) + 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) + { + tmpde = doc_e->user_data; + tmpde->user_data2 |= DEF2_PROCESSED; + tmpde2 = tmpde->parent; + if (!tmpde2 || !(tmpde2->user_data2 & DEF2_PROCESSED)) + { Silent; - Copy(tmpde->full_name,tmpde1->full_name); + Copy(tmpde->full_name, tmpde1->full_name); Silent(OFF); } - } 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)) { + } + 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)) + { Silent; if (*tmpde1->name) - st=MStrPrint("%s/%s",tmpde1->full_name,tmpde->name); + st = MStrPrint("%s/%s", tmpde1->full_name, tmpde->name); else - st=MStrPrint("%s%s",tmpde1->full_name,tmpde->name); - CopyTree(tmpde->full_name,st); + st = MStrPrint("%s%s", tmpde1->full_name, tmpde->name); + CopyTree(tmpde->full_name, st); Free(st); Silent(OFF); } } - doc_e=doc_e->next; + doc_e = doc_e->next; } } if (unlock_doc2) @@ -488,193 +555,221 @@ U0 FMCopy(CDoc *doc) #define FMR_BURN_ISO 11 #define FMR_HELP 12 -I64 PopUpFMRight(U8 *header=NULL,U8 *footer=NULL) +I64 PopUpFMRight(U8 *header=NULL, U8 *footer=NULL) { I64 i; - CDoc *doc=DocNew; - 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$$" - "$$CM+LX,29,0$$$$BT,\"RENAME \",LE=FMR_RENAME$$" - "$$CM+LX,1,3 $$$$BT,\"MAKE DIRECTORY \",LE=FMR_MKDIR$$" - "$$CM+LX,29,0$$$$BT,\"PASTE CLIP FILES \",LE=FMR_PASTE$$" - "$$CM+LX,1,3 $$$$BT,\"CHANGE DISK(MOUNT IT) \",LE=FMR_CHG_DISK$$" - "$$CM+LX,29,0$$$$BT,\"FORMAT \",LE=FMR_FORMAT$$" - "$$CM+LX,1,3 $$$$BT,\"MOUNT ISO.C FILE \",LE=FMR_MOUNT_REDSEA_ISO_C$$" - "$$CM+LX,29,0$$$$BT,\"UNMOUNT \",LE=FMR_UNMOUNT$$" - "$$CM+LX,1,3 $$$$BT,\"MAKE ISO.C (CD/DVD) FILE\",LE=FMR_MAKE_REDSEA_ISO_C$$" - "$$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); - i=PopUpMenu(doc); + CDoc *doc = DocNew; + 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$$" + "$$CM+LX,29,0$$$$BT,\"RENAME \",LE=FMR_RENAME$$" + "$$CM+LX,1,3 $$$$BT,\"MAKE DIRECTORY \",LE=FMR_MKDIR$$" + "$$CM+LX,29,0$$$$BT,\"PASTE CLIP FILES \",LE=FMR_PASTE$$" + "$$CM+LX,1,3 $$$$BT,\"CHANGE DISK(MOUNT IT) \",LE=FMR_CHG_DISK$$" + "$$CM+LX,29,0$$$$BT,\"FORMAT \",LE=FMR_FORMAT$$" + "$$CM+LX,1,3 $$$$BT,\"MOUNT ISO.C FILE \",LE=FMR_MOUNT_REDSEA_ISO_C$$" + "$$CM+LX,29,0$$$$BT,\"UNMOUNT \",LE=FMR_UNMOUNT$$" + "$$CM+LX,1,3 $$$$BT,\"MAKE ISO.C (CD/DVD) FILE\",LE=FMR_MAKE_REDSEA_ISO_C$$" + "$$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); + i = PopUpMenu(doc); DocDel(doc); return i; } U0 FMRightClick() { - switch (PopUpFMRight) { + switch (PopUpFMRight) + { case FMR_INCLUDE: - Message(MESSAGE_KEY_DOWN,0,0x3F0000003F); + Message(MESSAGE_KEY_DOWN, 0, 0x3F0000003F); break; case FMR_ZENITH_INCLUDE: - Message(MESSAGE_KEY_DOWN,0,0x23F0000023F); + Message(MESSAGE_KEY_DOWN, 0, 0x23F0000023F); break; case FMR_DELETE: - Message(MESSAGE_KEY_DOWN,CH_CTRLY,0); + Message(MESSAGE_KEY_DOWN, CH_CTRLY, 0); break; case FMR_RENAME: - Message(MESSAGE_KEY_DOWN,'r',0); + Message(MESSAGE_KEY_DOWN, 'r', 0); break; case FMR_MKDIR: - Message(MESSAGE_KEY_DOWN,'d',0); + Message(MESSAGE_KEY_DOWN, 'd', 0); break; case FMR_PASTE: - Message(MESSAGE_KEY_DOWN,0,SC_INS+SCF_SHIFT); + Message(MESSAGE_KEY_DOWN, 0, SC_INS + SCF_SHIFT); break; case FMR_CHG_DISK: - Message(MESSAGE_KEY_DOWN,'c',0); + Message(MESSAGE_KEY_DOWN, 'c', 0); break; case FMR_FORMAT: - Message(MESSAGE_KEY_DOWN,'f',0); + Message(MESSAGE_KEY_DOWN, 'f', 0); break; case FMR_MOUNT_REDSEA_ISO_C: - Message(MESSAGE_KEY_DOWN,'i',0); + Message(MESSAGE_KEY_DOWN, 'i', 0); break; case FMR_UNMOUNT: - Message(MESSAGE_KEY_DOWN,'u',0); + Message(MESSAGE_KEY_DOWN, 'u', 0); break; case FMR_MAKE_REDSEA_ISO_C: - Message(MESSAGE_KEY_DOWN,'m',0); + Message(MESSAGE_KEY_DOWN, 'm', 0); break; case FMR_BURN_ISO: - Message(MESSAGE_KEY_DOWN,'B',0); + Message(MESSAGE_KEY_DOWN, 'B', 0); break; case FMR_HELP: - Message(MESSAGE_KEY_DOWN,CH_CTRLM,0x43200000432); + Message(MESSAGE_KEY_DOWN, CH_CTRLM, 0x43200000432); break; } } -U8 *fm_mouse_str=NULL; +U8 *fm_mouse_str = NULL; U0 (*fp_old_final_screen_update)(CDC *dc); U0 FMFinalScreenUpdate(CDC *dc) { - if (fm_mouse_str) { - dc->color=LTRED; - GrPrint(dc,mouse.pos.x,mouse.pos.y,"%s",fm_mouse_str); + if (fm_mouse_str) + { + dc->color = LTRED; + GrPrint(dc, mouse.pos.x, mouse.pos.y, "%s", fm_mouse_str); } (*fp_old_final_screen_update)(dc); } -public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL) +public U8 *FileMgr(I64 mode=FM_NORMAL, CTask *mem_task=NULL) {//File manager. Also, used to choose files and dirs. - CDirEntry *head=NULL,*tmpde,*tmpde1,*tmpde2; - I64 sc,ch,arg1,arg2,message_code; - CDoc *doc=NULL,*old_put_doc=DocPut,*old_display_doc=DocDisplay; - U8 *res=NULL,*st,*st2,*old_cur_dir=DirCur; - CDocEntry *doc_ce=NULL,*doc_e; + CDirEntry *head = NULL, *tmpde, *tmpde1, *tmpde2; + I64 sc, ch, arg1, arg2, message_code; + CDoc *doc = NULL, *old_put_doc = DocPut, *old_display_doc = DocDisplay; + U8 *res = NULL, *st, *st2, *old_cur_dir = DirCur; + CDocEntry *doc_ce = NULL, *doc_e; Bool okay; SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$ - fp_old_final_screen_update=gr.fp_final_screen_update; + fp_old_final_screen_update = gr.fp_final_screen_update; MenuFilePush("::/Doc/FileMgrPullDown.DD"); - FMRebuildDoc(&doc,&head,mode); - if (tmpde1=Cd2DirEntry(head,old_cur_dir)) - doc->cur_entry=tmpde1->user_data; - while (tmpde1) { - if (tmpde1->attr&RS_ATTR_DIR) - tmpde1->user_data(CDocEntry *)->de_flags&=~DOCEF_CHECKED_COLLAPSED; - tmpde1=tmpde1->parent; + FMRebuildDoc(&doc, &head, mode); + if (tmpde1 = Cd2DirEntry(head, old_cur_dir)) + doc->cur_entry = tmpde1->user_data; + 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<cur_entry; - fm_mouse_str=doc_ce->tag; - gr.fp_final_screen_update=&FMFinalScreenUpdate; + doc_ce = doc->cur_entry; + fm_mouse_str = doc_ce->tag; + gr.fp_final_screen_update = &FMFinalScreenUpdate; break; case MESSAGE_MS_L_UP: - 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)) { - doc_e=doc->cur_entry; - if (doc_e!=doc_ce) { - st2=NULL; - 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) { - tmpde1=doc_e->user_data; - st2=StrNew(tmpde1->full_name); + 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)) + { + doc_e = doc->cur_entry; + if (doc_e != doc_ce) + { + st2 = NULL; + if (doc_e->type_u8 == DOCT_MENU_VAL) + { + tmpde1 = doc_e->user_data; + if (tmpde1 = tmpde1->parent) + st2 = StrNew(tmpde1->full_name); } - if (st2 && doc_ce->type_u8==DOCT_MENU_VAL) { - tmpde=doc_ce->user_data; + 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) + { + tmpde = doc_ce->user_data; Silent; - Move(tmpde->full_name,st2); + Move(tmpde->full_name, st2); Silent(OFF); - FMRebuildDoc(&doc,&head,mode); - } else if (st2 && doc_ce->type_u8==DOCT_TREE) { - tmpde=doc_ce->user_data; - okay=TRUE; - tmpde2=tmpde1; - while (tmpde2) { - if (tmpde2!=tmpde) - tmpde2=tmpde2->parent; - else { - okay=FALSE; + FMRebuildDoc(&doc, &head, mode); + } + else if (st2 && doc_ce->type_u8 == DOCT_TREE) + { + tmpde = doc_ce->user_data; + okay = TRUE; + tmpde2 = tmpde1; + while (tmpde2) + { + if (tmpde2 != tmpde) + tmpde2 = tmpde2->parent; + else + { + okay = FALSE; break; } } - if (okay) { + if (okay) + { if (*tmpde1->name) - st=MStrPrint("%s/%s",tmpde1->full_name,tmpde->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)) { + st = MStrPrint("%s%s", tmpde1->full_name, tmpde->name); + if (StrCompare(tmpde->full_name, st)) + { Silent; - CopyTree(tmpde->full_name,st); + CopyTree(tmpde->full_name, st); DelTree(tmpde->full_name); Silent(OFF); - FMRebuildDoc(&doc,&head,mode); + FMRebuildDoc(&doc, &head, mode); } Free(st); } } 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); } - doc_ce=NULL; + doc_ce = NULL; } } break; case MESSAGE_KEY_DOWN: - doc_ce=NULL; - 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) { + doc_ce = NULL; + 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) + { case '\n': DocUnlock(doc); FMRightClick; @@ -713,65 +808,75 @@ public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL) FMFormatDrive(doc); break; end: - FMRebuildDoc(&doc,&head,mode); + FMRebuildDoc(&doc, &head, mode); break; 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: - doc_ce=doc->cur_entry; - 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) { - 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)) - res=StrNew(tmpde->full_name,mem_task); + doc_ce = doc->cur_entry; + 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) + { + 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)) + 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) { - tmpde=doc->cur_entry->user_data; + FMRebuildDoc(&doc, &head, mode); + } + 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) + if (sc & SCF_SHIFT) ZenithFile(tmpde->full_name); else PopUpFile(tmpde->full_name); DocLock(doc); } - } else { + } + else + { fm_regular_key: DocUnlock(doc); - PutKey(ch,sc); + PutKey(ch, sc); DocLock(doc); } } break; } - } 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; + } + 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; SettingsPop; DocDel(doc); DirTreeDel(head); Cd(old_cur_dir); Free(old_cur_dir); - if (mode!=FM_NORMAL && !res) - res=StrNew("",mem_task); + if (mode != FM_NORMAL && !res) + res = StrNew("", mem_task); MenuPop; return res; } diff --git a/src/Zenith/ZBlkDev/ZDiskA.CC b/src/Zenith/ZBlkDev/ZDiskA.CC index 0b229e56..b6afd110 100755 --- a/src/Zenith/ZBlkDev/ZDiskA.CC +++ b/src/Zenith/ZBlkDev/ZDiskA.CC @@ -1,154 +1,175 @@ #help_index "File/Cmd Line (Typically);Cmd Line (Typically)" -public U8 *DBlk(I64 blk,Bool write=FALSE) +public U8 *DBlk(I64 blk, Bool write=FALSE) {//Dump disk block. Optionally, write. //If you set write to TRUE, the block will //be written when you press . //See $LK,"::/Demo/Disk/DiskRaw.CC"$. - U8 *buf=MAlloc(BLK_SIZE); + U8 *buf = MAlloc(BLK_SIZE); - BlkRead(Fs->cur_dv,buf,blk,1); - DocD(buf,BLK_SIZE); - if (write) { + BlkRead(Fs->cur_dv, buf, blk, 1); + DocD(buf, BLK_SIZE); + if (write) + { "Edit and press to write or \n"; - if (View) { + if (View) + { "Write\n"; - BlkWrite(Fs->cur_dv,buf,blk,1); + BlkWrite(Fs->cur_dv, buf, blk, 1); } } return buf; } -public U8 *DClus(I64 c,Bool write=FALSE,I64 num=0) +public U8 *DClus(I64 c, Bool write=FALSE, I64 num=0) {//Dump disk clus. Optionally, write. //If you set write to TRUE, the clus will //be written when you press . //See $LK,"::/Demo/Disk/DiskRaw.CC"$. //Do $LK,"Dir",A="MN:Dir"$("*",TRUE); to get clus numbers of files. - U8 *buf=MAlloc(Fs->cur_dv->spc<cur_dv,c,num); - ClusRead(Fs->cur_dv,buf,c,1); - "Clus:%X\n",c; - DocD(buf,Fs->cur_dv->spc<cur_dv->spc << BLK_SIZE_BITS); + c = ClusNumNext(Fs->cur_dv, c, num); + ClusRead(Fs->cur_dv, buf, c, 1); + "Clus:%X\n", c; + DocD(buf, Fs->cur_dv->spc << BLK_SIZE_BITS); + if (write) + { "Edit and press to write or \n"; - if (View) { + if (View) + { "Write\n"; - ClusWrite(Fs->cur_dv,buf,c,1); + ClusWrite(Fs->cur_dv, buf, c, 1); } } return buf; } -public U8 *Dump(U8 *filename,Bool write=FALSE) +public U8 *Dump(U8 *filename, Bool write=FALSE) {//Dump file. Optionally, write. //If you set write to TRUE, the file will //be written when you press . U8 *buf; I64 size; - if (buf=FileRead(filename,&size)) { - DocD(buf,size); - if (write) { + if (buf = FileRead(filename,&size)) + { + DocD(buf, size); + if (write) + { "Edit and press to write or \n"; - if (View) { + if (View) + { "Write\n"; - FileWrite(filename,buf,size); + FileWrite(filename, buf, size); } } } return buf; } -public Bool Copy(U8 *src_files_find_mask,U8 *dst_files_find_mask=".") +public Bool Copy(U8 *src_files_find_mask, U8 *dst_files_find_mask=".") {//Copy files. //If the name ends in ".Z", it will //be stored compressed. If not ".Z" //it will be stored uncompressed. - Bool res=TRUE; + Bool res = TRUE; CDirContext *dirc; - CDirEntry *tmpde,*tmpde1; + CDirEntry *tmpde, *tmpde1; U8 *st; - if (!(tmpde1=FilesFind(src_files_find_mask,FUF_CLUS_ORDER))) + 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)) { - tmpde=tmpde1; - while (tmpde) { - if (!(tmpde->attr & RS_ATTR_DIR)) { - st=FileNameAbs(tmpde->name); - if (!CopySingle(tmpde->full_name,st)) - res=FALSE; + if (IsDir(dst_files_find_mask)) + { + if (dirc = DirContextNew(dst_files_find_mask, TRUE)) + { + tmpde = tmpde1; + while (tmpde) + { + if (!(tmpde->attr & RS_ATTR_DIR)) + { + st = FileNameAbs(tmpde->name); + if (!CopySingle(tmpde->full_name, st)) + res = FALSE; Free(st); } - tmpde=tmpde->next; + tmpde = tmpde->next; } DirContextDel(dirc); } DirTreeDel(tmpde1); return res; - } else { + } + else + { DirTreeDel(tmpde1); - return CopySingle(src_files_find_mask,dst_files_find_mask); + return CopySingle(src_files_find_mask, dst_files_find_mask); } } -public Bool Move(U8 *f1,U8 *f2) +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; } return FALSE; } -I64 CopyTree2(CDirEntry *tmpde,I64 src_dir_len,I64 dst_dir_len,U8 *dst_dir) +I64 CopyTree2(CDirEntry *tmpde, I64 src_dir_len, I64 dst_dir_len, U8 *dst_dir) { U8 *st; - I64 res=1; - 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) { - DirMake(st,LinkedListCount(tmpde->sub)); - res+=CopyTree2(tmpde->sub,src_dir_len,dst_dir_len,dst_dir); - } else - if (CopySingle(tmpde->full_name,st)) + I64 res = 1; + 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) + { + DirMake(st, LinkedListCount(tmpde->sub)); + res += CopyTree2(tmpde->sub, src_dir_len, dst_dir_len, dst_dir); + } + else + if (CopySingle(tmpde->full_name, st)) res++; Free(st); - tmpde=tmpde->next; + tmpde = tmpde->next; } 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; - CDirEntry *tmpde=NULL; - I64 res=0,i1,i2; - U8 *st1,*st2; + CDirEntry *tmpde = NULL; + I64 res = 0, i1, i2; + U8 *st1, *st2; - st1=DirNameAbs(src_files_find_mask); - st2=DirNameAbs(dst_files_find_mask); - i1=StrLen(st1); - if (!StrNCompare(st1,st2,i1) && (st2[i1]=='/' || !st2[i1]) ) { + st1 = DirNameAbs(src_files_find_mask); + st2 = DirNameAbs(dst_files_find_mask); + i1 = StrLen(st1); + 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)) { - tmpde=FilesFind(dirc->mask,FUF_RECURSE); - st1=DirCur; + 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)) { - st2=DirCur; - i2=StrLen(st2); - if (i2==3) i2--; - res=CopyTree2(tmpde,i1,i2,st2); + i1 = StrLen(st1); + if (i1 == 3) + i1--; + if (dirc = DirContextNew(dst_files_find_mask, TRUE, TRUE)) + { + st2 = DirCur; + i2 = StrLen(st2); + if (i2 == 3) + i2--; + res = CopyTree2(tmpde, i1, i2, st2); DirContextDel(dirc); Free(st2); } @@ -160,77 +181,86 @@ public I64 CopyTree(U8 *src_files_find_mask,U8 *dst_files_find_mask, I64 DelTreeDirs(CDirEntry *tmpde1) { - I64 res=0; + I64 res = 0; CDirEntry *tmpde2; - while (tmpde1) { - tmpde2=tmpde1->next; - if (tmpde1->attr & RS_ATTR_DIR) { + while (tmpde1) + { + tmpde2 = tmpde1->next; + if (tmpde1->attr & RS_ATTR_DIR) + { if (tmpde1->sub) - res+=DelTreeDirs(tmpde1->sub); - res+=Del(tmpde1->full_name,TRUE,TRUE); + res += DelTreeDirs(tmpde1->sub); + res += Del(tmpde1->full_name, TRUE, TRUE); } DirEntryDel(tmpde1); - tmpde1=tmpde2; + tmpde1 = tmpde2; } return res; } I64 DelTreeFiles(CDirEntry *tmpde1) { - I64 res=0; + I64 res = 0; CDirEntry *tmpde2; - while (tmpde1) { - tmpde2=tmpde1->next; - if (tmpde1->attr & RS_ATTR_DIR) { + while (tmpde1) + { + tmpde2 = tmpde1->next; + if (tmpde1->attr & RS_ATTR_DIR) + { if (tmpde1->sub) - res+=DelTreeFiles(tmpde1->sub); - } else - res+=Del(tmpde1->full_name,FALSE,TRUE); + res += DelTreeFiles(tmpde1->sub); + } + else + res += Del(tmpde1->full_name, FALSE, TRUE); DirEntryDel(tmpde1); - tmpde1=tmpde2; + tmpde1 = tmpde2; } return res; } -public I64 DelTree(U8 *files_find_mask,U8 *fu_flags=NULL) +public I64 DelTree(U8 *files_find_mask, U8 *fu_flags=NULL) {//Delete directory tree. - 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)) { - res=DelTreeDirs(FilesFind(files_find_mask,fuf_flags)); - res+=Del(files_find_mask,TRUE,TRUE); - res+=Del(files_find_mask,FALSE,TRUE); - } else - res=DelTreeFiles(FilesFind(files_find_mask,fuf_flags)); + 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)) + { + res = DelTreeDirs(FilesFind(files_find_mask, fuf_flags)); + res += Del(files_find_mask, TRUE, TRUE); + res += Del(files_find_mask, FALSE, TRUE); + } + else + res = DelTreeFiles(FilesFind(files_find_mask, fuf_flags)); return res; } -U0 TouchFile(U8 *filename,U8 *attr,CDate cdt=I64_MIN) +U0 TouchFile(U8 *filename, U8 *attr, CDate cdt=I64_MIN) { - CDrive *drive=Letter2Drive(*filename); + CDrive *drive = Letter2Drive(*filename); CDirEntry de; - U8 *cur_dir=StrNew(filename),buf[STR_LEN]; - if (FileFind(filename,&de,FUF_JUST_FILES)) { + U8 *cur_dir = StrNew(filename), buf[STR_LEN]; + 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 { - StrFirstRemove(cur_dir,":"); - StrLastRemove(cur_dir,"/"); + if (!StrCompare(attr, "+?")) + "%-48ts %s\n", filename, FlagsStrPrint(buf, Define("ST_FILE_ATTRS"), de.attr); + else + { + StrFirstRemove(cur_dir, ":"); + StrLastRemove(cur_dir, "/"); if (!*cur_dir) - StrCopy(cur_dir,"/"); - FlagsScan(&de.attr,Define("ST_FILE_ATTRS"),attr); - if (cdt==I64_MIN) - de.datetime=Now; + StrCopy(cur_dir, "/"); + FlagsScan(&de.attr, Define("ST_FILE_ATTRS"), attr); + if (cdt == I64_MIN) + de.datetime = Now; else - de.datetime=cdt; - DirNew(drive,cur_dir,&de,FALSE); + de.datetime = cdt; + DirNew(drive, cur_dir, &de, FALSE); } - } else - PrintErr("File not found: \"%s\".\n",filename); + } + 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 @@ -239,14 +269,15 @@ $LK,"RS_ATTR_READ_ONLY",A="MN:RS_ATTR_READ_ONLY"$ $LK,"ST_FILE_ATTRS",A="MN:ST_ To Set DateL: Touch(filename,"",,datetime); */ - I64 fuf_flags=0; - CDirEntry *tmpde,*tmpde1; - 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) { - TouchFile(tmpde->full_name,attr,cdt); - tmpde=tmpde->next; + I64 fuf_flags = 0; + CDirEntry *tmpde, *tmpde1; + 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) + { + TouchFile(tmpde->full_name, attr, cdt); + tmpde = tmpde->next; } DirTreeDel(tmpde1); } diff --git a/src/Zenith/ZBlkDev/ZDiskB.CC b/src/Zenith/ZBlkDev/ZDiskB.CC index 97245c63..dc498fd1 100755 --- a/src/Zenith/ZBlkDev/ZDiskB.CC +++ b/src/Zenith/ZBlkDev/ZDiskB.CC @@ -1,79 +1,89 @@ #help_index "File/Internal" I64 DirTreeSerializeSize(CDirEntry *tmpde) { - I64 res=0; - while (tmpde) { - res+=CDIR_SIZE+1; + I64 res = 0; + while (tmpde) + { + res += CDIR_SIZE + 1; if (tmpde->attr & RS_ATTR_DIR) - res+=DirTreeSerializeSize(tmpde->sub); - tmpde=tmpde->next; + res += DirTreeSerializeSize(tmpde->sub); + tmpde = tmpde->next; } - return res+1; + return res + 1; } -I64 DirTreeSerializeFill(CDirEntry *tmpde,U8 *dst) +I64 DirTreeSerializeFill(CDirEntry *tmpde, U8 *dst) { - I64 res=0,i; - while (tmpde) { - *dst++=1; + I64 res = 0, i; + while (tmpde) + { + *dst++ = 1; res++; - MemCopy(dst,&tmpde->start,CDIR_SIZE); - dst+=CDIR_SIZE; - res+=CDIR_SIZE; - if (tmpde->attr & RS_ATTR_DIR) { - i=DirTreeSerializeFill(tmpde->sub,dst); - dst+=i; - res+=i; + MemCopy(dst, &tmpde->start, CDIR_SIZE); + dst += CDIR_SIZE; + res += CDIR_SIZE; + if (tmpde->attr & RS_ATTR_DIR) + { + i = DirTreeSerializeFill(tmpde->sub, dst); + dst += i; + res += i; } - tmpde=tmpde->next; + tmpde = tmpde->next; } - *dst=0; - return res+1; + *dst = 0; + return res + 1; } -public U8 *DirTreeSerialize(CDirEntry *tmpde,I64 *_size=NULL) +public U8 *DirTreeSerialize(CDirEntry *tmpde, I64 *_size=NULL) {//Serialize tree returned from $LK,"FilesFind",A="MN:FilesFind"$() into a one contiguous U8 array. - I64 size=DirTreeSerializeSize(tmpde); - U8 *buf=MAlloc(size); - DirTreeSerializeFill(tmpde,buf); - if (_size) *_size=size; + I64 size = DirTreeSerializeSize(tmpde); + U8 *buf = MAlloc(size); + DirTreeSerializeFill(tmpde, buf); + if (_size) + *_size = size; return buf; } -U8 *DirTreeUnserialize2(U8 *src,CDirEntry **tmpde) +U8 *DirTreeUnserialize2(U8 *src, CDirEntry **tmpde) { CDirEntry *tmpde1; - if (*src++) { - tmpde1=CAlloc(sizeof(CDirEntry)); - *tmpde=tmpde1; - MemCopy(&tmpde1->start,src,CDIR_SIZE); - src+=CDIR_SIZE; + if (*src++) + { + tmpde1 = CAlloc(sizeof(CDirEntry)); + *tmpde = tmpde1; + MemCopy(&tmpde1->start, src, CDIR_SIZE); + src += CDIR_SIZE; if (tmpde1->attr & RS_ATTR_DIR) - src=DirTreeUnserialize2(src,&tmpde1->sub); - src=DirTreeUnserialize2(src,&tmpde1->next); - } else - *tmpde=NULL; + src = DirTreeUnserialize2(src, &tmpde1->sub); + src = DirTreeUnserialize2(src, &tmpde1->next); + } + else + *tmpde = NULL; return src; } public CDirEntry *DirTreeUnserialize(U8 *src) {//Unserialize tree to make it like a tree returned from $LK,"FilesFind",A="MN:FilesFind"$(). - CDirEntry *tmpde=NULL; - DirTreeUnserialize2(src,&tmpde); + CDirEntry *tmpde = NULL; + DirTreeUnserialize2(src, &tmpde); return tmpde; } #help_index "File/Program Routines" -U0 FOFlatten(CDirEntry *tmpde,CDirEntry **a,I64 *i) +U0 FOFlatten(CDirEntry *tmpde, CDirEntry **a, I64 *i) { CDirEntry *tmpde1; - while (tmpde) { - tmpde1=tmpde->next; - if (tmpde->attr&RS_ATTR_DIR) { - FOFlatten(tmpde->sub,a,i); + while (tmpde) + { + tmpde1 = tmpde->next; + if (tmpde->attr & RS_ATTR_DIR) + { + FOFlatten(tmpde->sub, a, i); DirEntryDel(tmpde); - } else { - a[*i]=tmpde; - *i=*i+1; } - tmpde=tmpde1; + else + { + a[*i] = tmpde; + *i = *i + 1; + } + tmpde = tmpde1; } } @@ -82,28 +92,28 @@ I64 Size1(CDirEntry *tmpde,I64 round_to) I64 res = 0, i; while (tmpde) { - i=tmpde->size; + i = tmpde->size; if (round_to) i = CeilU64(tmpde->size, round_to); if (tmpde->attr & RS_ATTR_DIR) i += Size1(tmpde->sub, round_to); - tmpde->user_data=i; //Store size in user_data member + tmpde->user_data = i; //Store size in user_data member res += i; tmpde = tmpde->next; } return res; } -public I64 Size(U8 *files_find_mask="/*",U8 *fu_flags=NULL,I64 round_to=0) +public I64 Size(U8 *files_find_mask="/*", U8 *fu_flags=NULL, I64 round_to=0) {//Total size of files in mask. //Does not include directory size of base directory, but does include size of sub directories. - I64 fuf_flags=0,res=0; - CDirEntry *tmpde1=NULL; - FlagsScan(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r"); - FlagsScan(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags); - if (tmpde1=FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND)) + I64 fuf_flags = 0, res = 0; + CDirEntry *tmpde1 = NULL; + FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), "+r"); + FlagsScan(&fuf_flags, Define("ST_FILE_UTIL_FLAGS"), fu_flags); + if (tmpde1 = FilesFind(files_find_mask, fuf_flags & FUG_FILES_FIND)) { - res=Size1(tmpde1,round_to); + res = Size1(tmpde1, round_to); DirTreeDel(tmpde1); } return res; @@ -111,30 +121,32 @@ 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) { - if (tmpde->attr&RS_ATTR_DIR) - count+=FileCount(tmpde->sub); + I64 count = 0; + while (tmpde) + { + if (tmpde->attr & RS_ATTR_DIR) + count += FileCount(tmpde->sub); else count++; - tmpde=tmpde->next; + tmpde = tmpde->next; } return count; } #help_index "File/Cmd Line (Typically);Cmd Line (Typically)" -public I64 FF(U8 *files_find_mask,U8 *fu_flags=NULL) +public I64 FF(U8 *files_find_mask, U8 *fu_flags=NULL) {//Files find. List files matching mask. - I64 count=0,fuf_flags=0; - CDirEntry *tmpde,*tmpde1; - 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) { + I64 count = 0, fuf_flags = 0; + CDirEntry *tmpde, *tmpde1; + 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) + { PutFileLink(tmpde->full_name); '\n'; count++; - tmpde=tmpde->next; + tmpde = tmpde->next; } DirTreeDel(tmpde1); return count;