Initial (manual) import

This commit is contained in:
minexew committed 2017-01-22 20:26:44 +01:00
1 parent f39611c506
commit 895fe109de
661 files changed
+245862

No files matched your search

+252
View File
@@ -0,0 +1,252 @@
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
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 <ESC>.
//See $LK,"::/Demo/Dsk/DskRaw.HC"$.
U8 *buf=MAlloc(BLK_SIZE);
RBlks(Fs->cur_dv,buf,blk,1);
DocD(buf,BLK_SIZE);
if (write) {
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
"Write\n";
WBlks(Fs->cur_dv,buf,blk,1);
}
}
return buf;
}
public U8 *DCluster(I64 c,Bool write=FALSE,I64 num=0)
{//Dump disk cluster. Optionally, write.
//If you set write to TRUE, the cluster will
//be written when you press <ESC>.
//See $LK,"::/Demo/Dsk/DskRaw.HC"$.
//Do $LK,"Dir",A="MN:Dir"$("*",TRUE); to get cluster numbers of files.
U8 *buf=MAlloc(Fs->cur_dv->spc<<BLK_SIZE_BITS);
c=ClusterNumNext(Fs->cur_dv,c,num);
RClusters(Fs->cur_dv,buf,c,1);
"Cluster:%X\n",c;
DocD(buf,Fs->cur_dv->spc<<BLK_SIZE_BITS);
if (write) {
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
"Write\n";
WClusters(Fs->cur_dv,buf,c,1);
}
}
return buf;
}
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 <ESC>.
U8 *buf;
I64 size;
if (buf=FileRead(filename,&size)) {
DocD(buf,size);
if (write) {
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
if (View) {
"Write\n";
FileWrite(filename,buf,size);
}
}
}
return buf;
}
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;
CDirContext *dirc;
CDirEntry *tmpde,*tmpde1;
U8 *st;
if (!(tmpde1=FilesFind(src_files_find_mask,FUF_CLUSTER_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;
Free(st);
}
tmpde=tmpde->next;
}
DirContextDel(dirc);
}
DirTreeDel(tmpde1);
return res;
} else {
DirTreeDel(tmpde1);
return CopySingle(src_files_find_mask,dst_files_find_mask);
}
}
public Bool Move(U8 *f1,U8 *f2)
{//Move files from one location to another or rename.
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)
{
U8 *st;
I64 res=1;
while (tmpde) {
st=MAlloc(StrLen(tmpde->full_name)+dst_dir_len+2);
MemCpy(st,dst_dir,dst_dir_len);
StrCpy(st+dst_dir_len,tmpde->full_name+src_dir_len);
if (tmpde->attr & RS_ATTR_DIR) {
MkDir(st,LinkedLstCnt(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;
}
return res;
}
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;
st1=DirNameAbs(src_files_find_mask);
st2=DirNameAbs(dst_files_find_mask);
i1=StrLen(st1);
if (!StrNCmp(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=CurDir;
DirContextDel(dirc);
i1=StrLen(st1);
if (i1==3) i1--;
if (dirc=DirContextNew(dst_files_find_mask,TRUE,TRUE)) {
st2=CurDir;
i2=StrLen(st2);
if (i2==3) i2--;
res=CopyTree2(tmpde,i1,i2,st2);
DirContextDel(dirc);
Free(st2);
}
DirTreeDel(tmpde);
Free(st1);
}
return res;
}
I64 DelTreeDirs(CDirEntry *tmpde1)
{
I64 res=0;
CDirEntry *tmpde2;
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);
}
DirEntryDel(tmpde1);
tmpde1=tmpde2;
}
return res;
}
I64 DelTreeFiles(CDirEntry *tmpde1)
{
I64 res=0;
CDirEntry *tmpde2;
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);
DirEntryDel(tmpde1);
tmpde1=tmpde2;
}
return res;
}
public I64 DelTree(U8 *files_find_mask,U8 *fu_flags=NULL)
{//Delete directory tree.
I64 res=0,fuf_flags=0;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
ScanFlags(&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)
{
CDrv *dv=Let2Drv(*filename);
CDirEntry de;
U8 *cur_dir=StrNew(filename),buf[STR_LEN];
if (FileFind(filename,&de,FUF_JUST_FILES)) {
Free(de.full_name);
if (!StrCmp(attr,"+?"))
"%-48ts %s\n",filename,StrPrintFlags(buf,Define("ST_FILE_ATTRS"),de.attr);
else {
StrFirstRem(cur_dir,":");
StrLastRem(cur_dir,"/");
if (!*cur_dir)
StrCpy(cur_dir,"/");
ScanFlags(&de.attr,Define("ST_FILE_ATTRS"),attr);
if (cdt==I64_MIN)
de.datetime=Now;
else
de.datetime=cdt;
DirNew(dv,cur_dir,&de,FALSE);
}
} else
PrintErr("File not found.\n");
Free(cur_dir);
}
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
"+T" =resident
$LK,"RS_ATTR_READ_ONLY",A="MN:RS_ATTR_READ_ONLY"$ $LK,"ST_FILE_ATTRS",A="MN:ST_FILE_ATTRS"$
To Set DateL:
Touch(filename,"",,datetime);
*/
I64 fuf_flags=0;
CDirEntry *tmpde,*tmpde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+f+F");
ScanFlags(&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);
}
+191
View File
@@ -0,0 +1,191 @@
#help_index "File/Internal"
I64 DirTreeSerializeSize(CDirEntry *tmpde)
{
I64 res=0;
while (tmpde) {
res+=CDIR_SIZE+1;
if (tmpde->attr & RS_ATTR_DIR)
res+=DirTreeSerializeSize(tmpde->sub);
tmpde=tmpde->next;
}
return res+1;
}
I64 DirTreeSerializeFill(CDirEntry *tmpde,U8 *dst)
{
I64 res=0,i;
while (tmpde) {
*dst++=1;
res++;
MemCpy(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;
}
*dst=0;
return res+1;
}
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;
return buf;
}
U8 *DirTreeUnserialize2(U8 *src,CDirEntry **tmpde)
{
CDirEntry *tmpde1;
if (*src++) {
tmpde1=CAlloc(sizeof(CDirEntry));
*tmpde=tmpde1;
MemCpy(&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;
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);
return tmpde;
}
#help_index "File/Program Routines"
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);
DirEntryDel(tmpde);
} else {
a[*i]=tmpde;
*i=*i+1;
}
tmpde=tmpde1;
}
}
I64 Size1(CDirEntry *tmpde,I64 *_fuf_flags,I64 round_to)
{
U8 buf[BLK_SIZE];
I64 res=0,i;
CDrv *dv;
while (tmpde) {
if ((i=tmpde->size) && Bt(_fuf_flags,FUf_EXPAND) &&
!(tmpde->attr&RS_ATTR_DIR) &&
FileAttr(tmpde->name)&RS_ATTR_COMPRESSED) {
dv=Let2Drv(*tmpde->full_name);
RBlks(dv,buf,Cluster2Blk(dv,tmpde->cluster),1);
i=(&buf)(CArcCompress *)->expanded_size;
}
if (round_to)
i=CeilU64(tmpde->size,round_to);
if (tmpde->attr&RS_ATTR_DIR)
i+=Size1(tmpde->sub,_fuf_flags,round_to);
tmpde->user_data=i;
res+=i;
tmpde=tmpde->next;
}
return res;
}
public I64 Size(U8 *files_find_mask="/*",U8 *fu_flags=NULL,I64 round_to=0)
{//Total size of files in mask. "+x" for expanded size.
//Does not include directory size of base directory, but
//does include size of sub directories.
I64 fuf_flags=0,res=0;
CDirEntry *tmpde1=NULL;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tmpde1=FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND)) {
fuf_flags&=FUF_EXPAND;
res=Size1(tmpde1,&fuf_flags,round_to);
DirTreeDel(tmpde1);
}
return res;
}
public I64 FileCnt(CDirEntry *tmpde)
{//Cnt of files in $LK,"CDirEntry",A="MN:CDirEntry"$ tree.
I64 cnt=0;
while (tmpde) {
if (tmpde->attr&RS_ATTR_DIR)
cnt+=FileCnt(tmpde->sub);
else
cnt++;
tmpde=tmpde->next;
}
return cnt;
}
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
public I64 FF(U8 *files_find_mask,U8 *fu_flags=NULL)
{//Files find. List files matching mask.
I64 cnt=0,fuf_flags=0;
CDirEntry *tmpde,*tmpde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
while (tmpde) {
PutFileLink(tmpde->full_name);
'\n';
cnt++;
tmpde=tmpde->next;
}
DirTreeDel(tmpde1);
return cnt;
}
public I64 Zip(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{//Compress files by moving to .Z filename.
U8 *st;
CDirEntry *tmpde,*tmpde1;
I64 res=0,fuf_flags=0;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
while (tmpde) {
if (!IsDotZ(tmpde->full_name)) {
st=MStrPrint("%s.Z",tmpde->full_name);
res+=Move(tmpde->full_name,st);
Free(st);
}
tmpde=tmpde->next;
}
DirTreeDel(tmpde1);
return res;
}
public I64 Unzip(U8 *files_find_mask="*.Z",U8 *fu_flags=NULL)
{//Uncompress files by moving to not .Z filename.
//You don't have to do this for normal operation.
//It automatically unzips ".Z" files.
U8 *st;
CDirEntry *tmpde,*tmpde1;
I64 res=0,fuf_flags=0;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
while (tmpde) {
if (IsDotZ(tmpde->full_name)) {
st=StrNew(tmpde->full_name);
StrLastRem(st,".");
res+=Move(tmpde->full_name,st);
Free(st);
}
tmpde=tmpde->next;
}
DirTreeDel(tmpde1);
return res;
}
+444
View File
@@ -0,0 +1,444 @@
#help_index "Info;File/Cmd Line (Typically);Cmd Line (Typically)"
Bool ChkDskConfirm(Bool *_fix,Bool *_confirm)
{
if (*_fix && *_confirm) {
"Fix ";
if (!YorN)
*_fix=FALSE;
*_confirm=FALSE;
}
return *_fix;
}
I64 RedSeaChkDskLst(CDrv *dv,CDirEntry *tmpde1,
U8 *bits,U8 *bits2,I64 size,I64 bpc)
{
CDirEntry *tmpde2;
I64 i,j,errs=0;
while (tmpde1) {
tmpde2=tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR && tmpde1->sub)
errs+=RedSeaChkDskLst(dv,tmpde1->sub,bits,bits2,size,bpc);
j=(tmpde1->size+bpc-1)/bpc;
for (i=0;i<j;i++) {
if (i+tmpde1->cluster-dv->data_area>size) {
PrintErr("Invalid Cluster:%s Cluster:%X\n",tmpde1->full_name,
i+tmpde1->cluster);
errs++;
break;
}
if (LBts(bits,i+tmpde1->cluster-dv->data_area)) {
PrintErr("Dbl Alloc:%s Cluster:%X\n",tmpde1->full_name,
i+tmpde1->cluster);
errs++;
}
if (!LBtr(bits2,i+tmpde1->cluster-dv->data_area)) {
PrintErr("UnAlloc:%s Cluster:%X\n",tmpde1->full_name,
i+tmpde1->cluster);
errs++;
}
}
DirEntryDel(tmpde1);
tmpde1=tmpde2;
}
return errs;
}
I64 RedSeaChkDsk(U8 drv_let,Bool *_fix,Bool *_confirm)
{
I64 i,j,bpc,size,errs=0;
CDrv *dv=Let2Drv(drv_let),*old_dv=Fs->cur_dv;
U8 *files_find_mask=MStrPrint("%c:/*",Drv2Let(dv)),
*old_dir=StrNew(Fs->cur_dir),
*bits,*bits2;
CDirEntry *ptr,*ptr2;
Drv(drv_let);
"Scanning...\n";
size=(dv->size-(dv->data_area-dv->drv_offset))/dv->spc;
bpc=dv->spc<<BLK_SIZE_BITS;
bits=CAlloc((size+7)>>3);
bits2=CAlloc((size+7)>>3+BLK_SIZE);
RBlks(dv,bits2,dv->fat1,((size+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS);
//Get Root Dir size
ptr2=MAlloc(bpc);
RBlks(dv,ptr2,dv->root_cluster,1);
ptr=ptr2(U8 *)-offset(CDirEntry.start);
j=(ptr->size+bpc-1)/bpc;
Free(ptr2);
for (i=0;i<j;i++) {
if (i+dv->root_cluster-dv->data_area>size) {
PrintErr("Invalid Cluster: RootDir Cluster:%X\n",i+dv->root_cluster);
errs++;
break;
}
if (LBts(bits,i+dv->root_cluster-dv->data_area)) {
PrintErr("Dbl Alloc: RootDir Cluster:%X\n",i+dv->root_cluster);
errs++;
}
if (!LBtr(bits2,i+dv->root_cluster-dv->data_area)) {
PrintErr("UnAlloc: RootDir Cluster:%X\n",i+dv->root_cluster);
errs++;
}
}
errs+=RedSeaChkDskLst(dv,FilesFind(files_find_mask,FUF_RECURSE),
bits,bits2,size,bpc);
for (i=1;i<size;i++)
if (Bt(bits2,i)) {
PrintWarn("Shouldn't Alloc Cluster:%0X\n",i+dv->data_area);
errs++;
if (ChkDskConfirm(_fix,_confirm))
RedSeaFreeClusters(dv,i+dv->data_area,1);
}
Free(files_find_mask);
Free(bits);
Free(bits2);
Drv(Drv2Let(old_dv));
Cd(old_dir);
Free(old_dir);
return errs;
}
I64 FAT32ChkDskLst(CDrv *dv,CDirEntry *tmpde1,
U8 *bits,U32 *bits2,I64 size,I64 bpc)
{
CDirEntry *tmpde2;
I64 i,c,errs=0;
while (tmpde1) {
tmpde2=tmpde1->next;
if (tmpde1->attr & RS_ATTR_DIR && tmpde1->sub)
errs+=FAT32ChkDskLst(dv,tmpde1->sub,bits,bits2,size,bpc);
i=0;
c=tmpde1->cluster;
while (0<c<0x0FFFFFF8) {
if (c>size) {
PrintErr("Invalid Cluster:%s Cluster:%X\n",tmpde1->full_name,c);
errs++;
break;
}
if (LBts(bits,c)) {
PrintErr("Dbl Alloc:%s Cluster:%X\n",tmpde1->full_name,c);
errs++;
}
if (!bits2[c]) {
PrintErr("UnAlloc:%s Cluster:%X\n",tmpde1->full_name,c);
errs++;
} else
bits2[c]=0;
c=ClusterNumNext(dv,c);
i++;
}
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);
errs++;
}
}
DirEntryDel(tmpde1);
tmpde1=tmpde2;
}
return errs;
}
I64 FAT32ChkDsk(U8 drv_let,Bool *_fix,Bool *_confirm)
{
I64 i,bpc,size,c,errs=0;
CDrv *dv=Let2Drv(drv_let),*old_dv=Fs->cur_dv;
U8 *files_find_mask=MStrPrint("%c:/*",Drv2Let(dv)),
*old_dir=StrNew(Fs->cur_dir),
*bits;
U32 *bits2;
Drv(drv_let);
"Scanning...\n";
size=(dv->size-(dv->data_area-dv->drv_offset))/dv->spc;
bpc=dv->spc<<BLK_SIZE_BITS;
bits=CAlloc((size+7)>>3);
bits2=CAlloc(size*4+BLK_SIZE);
RBlks(dv,bits2,dv->fat1,(size*4+BLK_SIZE-1)>>BLK_SIZE_BITS);
c=dv->root_cluster;
while (0<c<0x0FFFFFF8) {
if (c>size) {
PrintErr("Invalid Cluster: RootDir Cluster:%X\n",c);
errs++;
break;
}
if (LBts(bits,c)) {
PrintErr("Dbl Alloc: RootDir Cluster:%X\n",c);
errs++;
}
if (!bits2[c]) {
PrintErr("UnAlloc: RootDir Cluster:%X\n",c);
errs++;
} else
bits2[c]=0;
c=ClusterNumNext(dv,c);
}
errs+=FAT32ChkDskLst(dv,FilesFind(files_find_mask,FUF_RECURSE),
bits,bits2,size,bpc);
bits2[1]=0; //See $LK,"FAT32Fmt",A="MN:FAT32Fmt"$()
for (i=1;i<size;i++)
if (bits2[i]) {
PrintWarn("Shouldn't Alloc Cluster:%0X\n",i);
errs++;
if (ChkDskConfirm(_fix,_confirm))
FAT32FreeClusters(dv,i);
}
Free(files_find_mask);
Free(bits);
Free(bits2);
Drv(Drv2Let(old_dv));
Cd(old_dir);
Free(old_dir);
return errs;
}
public I64 ChkDsk(U8 drv_let=0,Bool fix=FALSE,Bool confirm=TRUE)
{//Check disk for allocation errors and, optionally, fix.
//You probably want to reformat and reinstall.
I64 errs=0;
CDrv *dv=Let2Drv(drv_let);
switch (dv->fs_type) {
case FSt_REDSEA:
errs=RedSeaChkDsk(drv_let,&fix,&confirm);
break;
case FSt_FAT32:
errs=FAT32ChkDsk(drv_let,&fix,&confirm);
break;
default:
PrintErr("File System Not Supported\n");
}
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";
}
return errs;
}
U0 RedSeaDrvView(U8 drv_let=0)
{
CDrv *dv=Let2Drv(drv_let);
I64 lohi,c1,i,x,y,l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
s=dv->size+dv->drv_offset-dv->data_area;
U8 *bitmap;
CDC *dc=DCAlias;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
WinMax;
WinBorder(ON);
DocCursor;
DocClear;
DCFill;
try {
i=((s+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS;
bitmap=MAlloc(i<<BLK_SIZE_BITS);
RBlks(dv,bitmap,dv->fat1,i);
i=0;
for (y=0;y<GR_HEIGHT-3*FONT_HEIGHT;y++) {
if (ScanKey)
break;
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);
i++;
}
}
Free(bitmap);
} catch
DrvUnlock(dv);
GetChar;
SettingsPop;
DCFill;
DCDel(dc);
}
U0 FAT32DrvView(U8 drv_let=0)
{
CDrv *dv=Let2Drv(drv_let);
I64 lohi,c1,i,x,y,l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
s=(dv->size+dv->spc-1)/dv->spc-(2+dv->data_area-dv->drv_offset);
U32 *bitmap;
CDC *dc=DCAlias;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
WinMax;
WinBorder(ON);
DocCursor;
DocClear;
DCFill;
try {
i=(s*4+BLK_SIZE-1)>>BLK_SIZE_BITS;
bitmap=MAlloc(i<<BLK_SIZE_BITS);
RBlks(dv,bitmap,dv->fat1,i);
i=0;
for (y=0;y<GR_HEIGHT-3*FONT_HEIGHT;y++) {
if (ScanKey)
break;
for (x=0;x<GR_WIDTH-FONT_WIDTH<<1;x++) {
lohi=i*s;
c1=lohi/l;
if (bitmap[c1])
dc->color=ROP_XOR+BLUE^TRANSPARENT;
else
dc->color=ROP_XOR+WHITE^TRANSPARENT;
GrPlot(dc,x,y);
i++;
}
}
Free(bitmap);
} catch
DrvUnlock(dv);
GetChar;
SettingsPop;
DCFill;
DCDel(dc);
}
public U0 DrvView(U8 drv_let=0)
{//Drive view. Graph the allocation map's fragmentation.
CDrv *dv=Let2Drv(drv_let),*old_dv=Fs->cur_dv;
Drv(drv_let);
switch (dv->fs_type) {
case FSt_REDSEA:
RedSeaDrvView(drv_let);
break;
case FSt_FAT32:
FAT32DrvView(drv_let);
break;
default:
PrintErr("File System Not Supported\n");
}
Drv(Drv2Let(old_dv));
}
public U0 DskView(U8 drv_let=0)
{//Disk view. Pie chart of partition sizes.
I64 i,j,attr,
h=Fs->pix_width,
v=Fs->pix_height,
radius;
CDrv *dv;
CBlkDev *bd=Let2BlkDev(drv_let);
CDC *dc=DCAlias;
F64 sect_start,sect_end;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
DocCursor;
DocClear;
DCFill;
if (h<v)
radius=0.4*h;
else
radius=0.4*v;
dc->color=BLACK;
GrCircle(dc,h>>1,v>>1,radius);
j=1;
for (i=0;i<DRVS_NUM;i++) {
dv=&blkdev.drvs[i];
if (bd==dv->bd && dv->fs_type) {
sect_start=-(dv->drv_offset*2*ã/(bd->max_blk+1));
sect_end =-((dv->drv_offset+dv->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=DrvTextAttrGet(Drv2Let(dv));
dc->color=attr&15;
GrPrint(dc,0,v-FONT_HEIGHT*j,"%C %-8Z",Drv2Let(dv),
dv->fs_type,"ST_DRV_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);
j++;
}
}
GetChar(,FALSE);
SettingsPop;
DCFill;
DCDel(dc);
}
I64 RedSeaUnusedDrvSpace(U8 drv_let=0)
{
CDrv *dv=Let2Drv(drv_let);
I64 res=0,i,l;
U8 *bitmap;
try {
l=dv->size+dv->drv_offset-dv->data_area;
i=((l+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS;
bitmap=MAlloc(i<<BLK_SIZE_BITS);
RBlks(dv,bitmap,dv->fat1,i);
for (i=0;i<l;i++)
if (!Bt(bitmap,i))
res++;
Free(bitmap);
} catch
DrvUnlock(dv);
return res*BLK_SIZE*dv->spc;
}
I64 FAT32UnusedDrvSpace(U8 drv_let=0)
{
CDrv *dv=Let2Drv(drv_let);
I64 res=0,i,l;
U32 *bitmap;
try {
l=(dv->size+dv->spc-1)/dv->spc-(2+dv->data_area-dv->drv_offset);
i=(l*4+BLK_SIZE-1)>>BLK_SIZE_BITS;
bitmap=MAlloc(i<<BLK_SIZE_BITS);
RBlks(dv,bitmap,dv->fat1,i);
for (i=0;i<l;i++)
if (!bitmap[i])
res++;
Free(bitmap);
} catch
DrvUnlock(dv);
return res*BLK_SIZE*dv->spc;
}
public I64 UnusedDrvSpace(U8 drv_let=0)
{//Returns unused size in bytes.
CDrv *dv=Let2Drv(drv_let),*old_dv=Fs->cur_dv;
U8 *old_dir=StrNew(Fs->cur_dir);
I64 res=0;
Drv(drv_let);
switch (dv->fs_type) {
case FSt_REDSEA:
res=RedSeaUnusedDrvSpace(drv_let);
break;
case FSt_FAT32:
res=FAT32UnusedDrvSpace(drv_let);
break;
default:
PrintErr("File System Not Supported\n");
}
Drv(Drv2Let(old_dv));
Cd(old_dir);
Free(old_dir);
return res;
}
+809
View File
@@ -0,0 +1,809 @@
#help_index "DolDoc/Output;StdOut/DolDoc"
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$$");
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");
}
tmpde=tmpde->next;
}
}
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
#define FM_NORMAL 0
#define FM_PICK_FILE 1
#define FM_PICK_DIR 2
class CFMUncollapsedLst
{
CFMUncollapsedLst *next;
U8 *name;
};
CFMUncollapsedLst *FMCollectUncollapsedLst(CDoc *doc)
{
CDocEntry *doc_e=doc->head.next;
CFMUncollapsedLst *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(CFMUncollapsedLst));
tmpc->next=res;
res=tmpc;
tmpc->name=StrNew(tmpde->full_name);
}
}
}
doc_e=doc_e->next;
}
return res;
}
U0 FMMarkUncollapsed(CDoc *doc,CFMUncollapsedLst *tmpc,
U8 *cur_entry,U8 *next_entry)
{
CDocEntry *doc_e=doc->head.next;
CFMUncollapsedLst *tmpc1;
CDirEntry *tmpde;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TREE) {
tmpde=doc_e->user_data;
tmpc1=tmpc;
while (tmpc1) {
if (!StrCmp(tmpc1->name,tmpde->full_name)) {
doc_e->de_flags&=~DOCEF_CHECKED_COLLAPSED;
break;
}
tmpc1=tmpc1->next;
}
if (cur_entry) {
if (!StrNCmp(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 (!StrNCmp(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) {
tmpde=doc_e->user_data;
if (cur_entry) {
if (!StrNCmp(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 (!StrNCmp(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 FMDelUncollapsedLst(CFMUncollapsedLst *tmpc)
{
CFMUncollapsedLst *tmpc1;
while (tmpc) {
tmpc1=tmpc->next;
Free(tmpc->name);
Free(tmpc);
tmpc=tmpc1;
}
}
CDirEntry *FMRebuildDocDrv(U8 drv_let,CDoc *doc,CDirEntry **_head,Bool init)
{
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);
if (init)
tmpde->sub=tmpde1=FilesFind(st,FUF_RECURSE);
else
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$$");
DocBottom(doc);
if (init) {
DirFileDoc(doc,tmpde1);
while (tmpde1) {
tmpde1->parent=tmpde;
tmpde1=tmpde1->next;
}
}
DocPrint(doc,"$$ID,-2$$");
return tmpde;
}
U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_head,I64 mode)
{
CDrv *dv;
I64 i;
CDoc *doc=*_doc,*doc2=sys_clipboard_doc,*parent_doc;
CFMUncollapsedLst *tmpc=NULL;
U8 *cur_entry=NULL,*next_entry=NULL;
CDocEntry *doc_ce;
CDirEntry *tmpde,*tmpde1,*cur_tree_entry;
if (!doc)
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;
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;
else
tmpde=NULL;
if (tmpde) {
tmpde1=tmpde->parent;
while (tmpde1) {
if (tmpde1==cur_tree_entry) {
tmpde=NULL;
break;
} else
tmpde1=tmpde1->parent;
}
if (tmpde)
break;
}
doc_ce=doc_ce->next;
}
if (tmpde)
next_entry=StrNew(tmpde->full_name);
tmpc=FMCollectUncollapsedLst(doc);
DocDel(doc);
}
if (*_head) {
DirTreeDel(*_head);
*_head=NULL;
}
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 <ESC>\n\n");
doc->flags|=DOCF_SIZE_MIN;
break;
case FM_PICK_DIR:
DocPrint(doc,"$$PURPLE$$Pick directory and press <ESC>\n\n");
doc->flags|=DOCF_SIZE_MIN;
break;
}
DocPrint(doc,"$$LTBLUE$$");
for (i=0;i<DRVS_NUM;i++) {
dv=&blkdev.drvs[i];
if (dv->bd->type==BDT_ATAPI) {
if (dv->bd->flags&BDF_INITIALIZED)
tmpde=FMRebuildDocDrv(Drv2Let(dv),doc,_head,TRUE);
else {
tmpde=FMRebuildDocDrv(Drv2Let(dv),doc,_head,FALSE);
tmpde->flags|=DEF_NOT_INITIALIZED;
}
} else if (dv->fs_type==FSt_REDSEA || dv->fs_type==FSt_FAT32)
FMRebuildDocDrv(Drv2Let(dv),doc,_head,TRUE);
}
DocTop(doc);
FMMarkUncollapsed(doc,tmpc,cur_entry,next_entry);
DocCenter(doc);
DocRst(doc2,TRUE);
FMDelUncollapsedLst(tmpc);
Free(cur_entry);
Free(next_entry);
*_doc=doc;
DocLock(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) {
Cd(parent->full_name);
StrCpy(fn.name,tmpde->name);
if (DocForm(&fn)) {
Silent;
Move(tmpde->name,fn.name);
Silent(OFF);
}
}
} else if (doc_e->type_u8==DOCT_TREE) {
tmpde=doc_e->user_data;
if (parent=tmpde->parent) {
Cd(parent->full_name);
StrCpy(fn.name,tmpde->name);
if (DocForm(&fn)) {
if (StrCmp(tmpde->name,fn.name)) {
Silent;
if (CopyTree(tmpde->name,fn.name))
DelTree(tmpde->name);
Silent(OFF);
}
}
}
}
}
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) {
Cd(parent->full_name);
if (DocForm(&fn)) {
Silent;
MkDir(fn.name);
Silent(OFF);
}
}
} else if (doc_e->type_u8==DOCT_TREE) {
tmpde=doc_e->user_data;
Cd(tmpde->full_name);
if (DocForm(&fn)) {
Silent;
MkDir(fn.name);
Silent(OFF);
}
}
}
U0 FMDelete(CDoc *doc)
{
U8 *st;
CDocEntry *doc_ce=doc->cur_entry;
CDirEntry *tmpde;
if (doc_ce->type_u8==DOCT_MENU_VAL) {
tmpde=doc_ce->user_data;
Silent;
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;
Silent;
st=MStrPrint("Delete: %s",tmpde->full_name);
if (PopUpCancelOk(st))
DelTree(tmpde->full_name);
Free(st);
Silent(OFF);
}
}
U0 FMChgDsk(CDoc *doc)
{
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;
else
tmpde=NULL;
if (tmpde) {
while (tmpde->parent)
tmpde=tmpde->parent;
Silent;
ChgDsk(*tmpde->full_name);
Silent(OFF);
}
}
U0 FMMountISO(CDoc *doc)
{
CDocEntry *doc_ce=doc->cur_entry;
CDirEntry *tmpde;
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;
CDirEntry *tmpde;
I64 drv_let;
if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL)
tmpde=doc_ce->user_data;
else
tmpde=NULL;
if (tmpde) {
while (tmpde->parent)
tmpde=tmpde->parent;
drv_let=*tmpde->full_name;
if (Let2BlkDev(drv_let)!=Let2BlkDev(':'))
Unmount(drv_let);
}
}
U0 FMFmtDrv(CDoc *doc)
{
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;
else
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)) {
Silent;
Fmt(*tmpde->full_name,,FALSE);
Silent(OFF);
}
}
Free(st);
}
U0 FMMakeISO(CDoc *doc,I64 type)
{
CDocEntry *doc_ce=doc->cur_entry;
CDirEntry *tmpde;
U8 *st;
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) {
Silent;
switch (type) {
case FSt_REDSEA:
RedSeaISO(,tmpde->full_name);
break;
case FSt_ISO9660:
if (tmpde->full_name[StrLen(tmpde->full_name)-1]=='/')
st=MStrPrint("%s*",tmpde->full_name);
else
st=MStrPrint("%s/*",tmpde->full_name);
ISO9660ISO(,st);
Free(st);
break;
}
Silent(OFF);
}
}
}
U0 FMBurnISO(CDoc *doc)
{
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;
else
tmpde=NULL;
if (tmpde) {
while (tmpde->parent)
tmpde=tmpde->parent;
Silent;
DVDImageWrite(*tmpde->full_name);
Silent(OFF);
}
}
U0 FMCopy(CDoc *doc)
{
CDoc *doc2=sys_clipboard_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;
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->flags|=DEF_PROCESSED;
tmpde2=tmpde->parent;
if (!tmpde2 || !(tmpde2->flags&DEF_PROCESSED)) {
Silent;
Copy(tmpde->full_name,tmpde1->full_name);
Silent(OFF);
}
} else if (doc_e->type_u8==DOCT_TREE) {
tmpde=doc_e->user_data;
tmpde->flags|=DEF_PROCESSED;
tmpde2=tmpde->parent;
if (!tmpde2 || !(tmpde2->flags&DEF_PROCESSED)) {
Silent;
if (*tmpde1->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);
Free(st);
Silent(OFF);
}
}
doc_e=doc_e->next;
}
}
if (unlock_doc2)
DocUnlock(doc2);
}
#define FMR_INCLUDE 0
#define FMR_ADAM_INCLUDE 1
#define FMR_DELETE 2
#define FMR_RENAME 3
#define FMR_MKDIR 4
#define FMR_PLAIN 5
#define FMR_PASTE 6
#define FMR_CHG_DSK 7
#define FMR_FORMAT 8
#define FMR_MOUNT_REDSEA_ISO_C 9
#define FMR_UNMOUNT 10
#define FMR_MAKE_REDSEA_ISO_C 11
#define FMR_MAKE_ISO9660 12
#define FMR_BURN_ISO 13
#define FMR_HELP 14
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,\"ADAM INCLUDE \",LE=FMR_ADAM_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,\"PLAIN-TEXT EDIT \",LE=FMR_PLAIN$$"
"$$CM+LX,1,3 $$$$BT,\"PASTE CLIPBOARD FILES \",LE=FMR_PASTE$$"
"$$CM+LX,29,0$$$$BT,\"CHANGE DISK(MOUNT IT) \",LE=FMR_CHG_DSK$$"
"$$CM+LX,1,3 $$$$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,\"MAKE ISO (CD/DVD) FILE \",LE=FMR_MAKE_ISO9660$$"
"$$CM+LX,1,3 $$$$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) {
case FMR_INCLUDE:
Msg(MSG_KEY_DOWN,0,0x3F0000003F);
break;
case FMR_ADAM_INCLUDE:
Msg(MSG_KEY_DOWN,0,0x23F0000023F);
break;
case FMR_DELETE:
Msg(MSG_KEY_DOWN,CH_CTRLY,0);
break;
case FMR_RENAME:
Msg(MSG_KEY_DOWN,'r',0);
break;
case FMR_MKDIR:
Msg(MSG_KEY_DOWN,'d',0);
break;
case FMR_PLAIN:
Msg(MSG_KEY_DOWN,CH_SHIFT_SPACE,0);
break;
case FMR_PASTE:
Msg(MSG_KEY_DOWN,0,SC_INS+SCF_SHIFT);
break;
case FMR_CHG_DSK:
Msg(MSG_KEY_DOWN,'c',0);
break;
case FMR_FORMAT:
Msg(MSG_KEY_DOWN,'f',0);
break;
case FMR_MOUNT_REDSEA_ISO_C:
Msg(MSG_KEY_DOWN,'i',0);
break;
case FMR_UNMOUNT:
Msg(MSG_KEY_DOWN,'u',0);
break;
case FMR_MAKE_REDSEA_ISO_C:
Msg(MSG_KEY_DOWN,'m',0);
break;
case FMR_MAKE_ISO9660:
Msg(MSG_KEY_DOWN,'M',0);
break;
case FMR_BURN_ISO:
Msg(MSG_KEY_DOWN,'B',0);
break;
case FMR_HELP:
Msg(MSG_KEY_DOWN,CH_CTRLM,0x43200000432);
break;
}
}
U8 *fm_ms_str=NULL;
U0 (*fp_old_final_scrn_update)(CDC *dc);
U0 FMFinalScrnUpdate(CDC *dc)
{
if (fm_ms_str) {
dc->color=LTRED;
GrPrint(dc,ms.pos.x,ms.pos.y,"%s",fm_ms_str);
}
(*fp_old_final_scrn_update)(dc);
}
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,msg_code;
CDoc *doc=NULL,*old_put_doc=DocPut,*old_display_doc=DocDisplay;
U8 *res=NULL,*st,*st2,*old_cur_dir=CurDir;
CDocEntry *doc_ce=NULL,*doc_e;
Bool okay;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
fp_old_final_scrn_update=gr.fp_final_scrn_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;
}
do {
DocUnlock(doc);
do msg_code=GetMsg(&arg1,&arg2,
1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_L_UP|1<<MSG_MS_R_UP);
while (Fs!=sys_focus_task);
DocLock(doc);
switch (msg_code) {
case MSG_MS_R_UP:
DocUnlock(doc);
FMRightClick;
DocLock(doc);
break;
case MSG_MS_L_DOWN:
doc_ce=doc->cur_entry;
fm_ms_str=doc_ce->tag;
gr.fp_final_scrn_update=&FMFinalScrnUpdate;
break;
case MSG_MS_L_UP:
if (doc_ce) {
gr.fp_final_scrn_update=fp_old_final_scrn_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 (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) {
tmpde=doc_ce->user_data;
okay=TRUE;
tmpde2=tmpde1;
while (tmpde2) {
if (tmpde2!=tmpde)
tmpde2=tmpde2->parent;
else {
okay=FALSE;
break;
}
}
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 (StrCmp(tmpde->full_name,st)) {
Silent;
CopyTree(tmpde->full_name,st);
DelTree(tmpde->full_name);
Silent(OFF);
FMRebuildDoc(&doc,&head,mode);
}
Free(st);
}
}
Free(st2);
FlushMsgs;
} else
if (doc_e->type_u8==DOCT_MENU_VAL) {
DocUnlock(doc);
Ed(doc_e->user_data(CDirEntry *)->full_name);
DocLock(doc);
}
doc_ce=NULL;
}
}
break;
case MSG_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) {
case '\n':
DocUnlock(doc);
FMRightClick;
DocLock(doc);
break;
start:
DocUnlock(doc);
case CH_CTRLV:
FMCopy(doc);
break;
case 'r':
FMRename(doc);
break;
case 'd':
FMMkDir(doc);
break;
case CH_CTRLY:
FMDelete(doc);
break;
case 'c':
FMChgDsk(doc);
break;
case 'i':
FMMountISO(doc);
break;
case 'u':
FMUnmount(doc);
break;
case 'M':
FMMakeISO(doc,FSt_ISO9660);
break;
case 'm':
FMMakeISO(doc,FSt_REDSEA);
break;
case 'B':
FMBurnISO(doc);
break;
case 'f':
FMFmtDrv(doc);
break;
end:
FMRebuildDoc(&doc,&head,mode);
break;
case CH_SHIFT_ESC:
break;
case CH_SPACE:
if (doc->cur_entry->type_u8==DOCT_MENU_VAL) {
DocUnlock(doc);
Ed(doc->cur_entry->user_data(CDirEntry *)->full_name);
DocLock(doc);
} else
goto fm_regular_key;
break;
case CH_SHIFT_SPACE:
if (doc->cur_entry->type_u8==DOCT_MENU_VAL) {
DocUnlock(doc);
Plain(doc->cur_entry->user_data(CDirEntry *)->full_name);
DocLock(doc);
} 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);
}
break;
default:
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;
DocUnlock(doc);
if (sc&SCF_SHIFT)
AdamFile(tmpde->full_name);
else
PopUpFile(tmpde->full_name);
DocLock(doc);
}
} else {
fm_regular_key:
DocUnlock(doc);
PutKey(ch,sc);
DocLock(doc);
}
}
break;
}
} while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
gr.fp_final_scrn_update=fp_old_final_scrn_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);
MenuPop;
return res;
}
+8
View File
@@ -0,0 +1,8 @@
Cd(__DIR__);;
#include "ADskA"
#include "ADskB"
#include "PrtDsk"
#include "Mount"
#include "ChkDsk"
#include "FileMgr"
Cd("..");;
+159
View File
@@ -0,0 +1,159 @@
#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically);"
U8 Mount2(U8 boot_drv_let,CDoc *_doc,Bool _caller_is_prtdsk)
{//If _doc, called by $LK,"::/Kernel/KCfg.HC"$ else called by $LK,"Mount",A="MN:Mount"$().
I64 cnt,total=0,num_hints,drv_let,type,unit,prt_num;
U8 blks_buf[STR_LEN],addr_buf[STR_LEN],base0_buf[STR_LEN],base1_buf[STR_LEN],
*filename=NULL,*filename2=NULL,res=0;
CATARep *head=NULL,*tmpha;
Bool whole_drv,make_free;
CDoc *doc;
if (boot_drv_let)
boot_drv_let=Let2Let(boot_drv_let);
do {
cnt=0;
if (!_doc)
DrvRep;
"\n****** Mount Drives ******\n"
"$$GREEN$$A$$FG$$-$$GREEN$$B$$FG$$ are RAM drives.\n"
"$$GREEN$$C$$FG$$-$$GREEN$$L$$FG$$ are ATA hard drives.\n"
"$$GREEN$$M$$FG$$-$$GREEN$$P$$FG$$ are ISO file read drives.\n"
"$$GREEN$$Q$$FG$$-$$GREEN$$S$$FG$$ are ISO file write drives.\n"
"$$GREEN$$T$$FG$$-$$GREEN$$Z$$FG$$ are ATAPI CD/DVD drives.\n"
"\nDrive Letter ($$PURPLE$$<ENTER>$$FG$$ to exit):";
drv_let=Let2Let(GetChar);
'\n';
if (type=Let2BlkDevType(drv_let)) {
whole_drv=FALSE;
if (_doc) { //Called by $LK,"::/Kernel/KCfg.HC"$
doc=_doc;
make_free=FALSE;
} else { //Called by $LK,"Mount",A="MN:Mount"$()
doc=DocNew;
DocPrint(doc,"CBlkDev *bd;\n");
make_free=TRUE;
}
unit=0;
prt_num=I64_MIN;
switch (type) {
case BDT_RAM:
"Addr of RAM disk ($$PURPLE$$<ENTER>$$FG$$ to MAlloc):";
GetS(addr_buf,STR_LEN);
case BDT_ISO_FILE_WRITE:
"Blks of 512 bytes:";
GetS(blks_buf,STR_LEN);
break;
case BDT_ISO_FILE_READ:
filename=GetStr("File Name:");
break;
case BDT_ATA:
prt_num=GetI64("Partition Num (Default=All):",prt_num);
case BDT_ATAPI:
num_hints=ATARep(,,&head);
if (type==BDT_ATAPI && boot_drv_let)
"<ENTER> to use booted CD/DVD\n"; //Only $LK,"::/Kernel/KCfg.HC"$
do {
if (num_hints)
"Enter dev number or\nport with $$PURPLE$$0x$$FG$$ prefix.\n"
"I/O Port Base0:\n";
else
"Include $$PURPLE$$0x$$FG$$ prefix.\nI/O Port Base0:\n";
GetS(base0_buf,STR_LEN);
} while (!Str2I64(base0_buf) && (type!=BDT_ATAPI || !boot_drv_let));
if (1<=Str2I64(base0_buf)<=num_hints) {
tmpha=ATARepFind(head,Str2I64(base0_buf));
StrPrint(base0_buf,"0x%X",tmpha->base0);
StrPrint(base1_buf,"0x%X",tmpha->base1);
unit=tmpha->unit;
} else if (type!=BDT_ATAPI || *base0_buf) {
if (type==BDT_ATAPI)
StrCpy(base1_buf,"0");
else
do {
"I/O Port Base1:\n";
GetS(base1_buf,STR_LEN);
} while (!Str2I64(base1_buf));
do {
"\t$$PURPLE$$0$$FG$$=Master\n\t$$PURPLE$$1$$FG$$=Slave\nUnit:";
unit=GetChar-'0';
} while (!(0<=unit<=1));
'\n';
}
LinkedLstDel(head);
break;
}
DocPrint(doc,"bd=BlkDevNextFreeSlot(\'%C\',%d);bd->unit=%d;\n",
drv_let,type,unit);
switch (type) {
case BDT_RAM:
if (!*addr_buf) StrCpy(addr_buf,"0");
DocPrint(doc,"bd->RAM_dsk=%s;\n",addr_buf);
case BDT_ISO_FILE_WRITE:
if (!*blks_buf) StrCpy(blks_buf,"0");
DocPrint(doc,"bd->max_blk=(%s)-1;\n",blks_buf);
DocPrint(doc,"bd->drv_offset=19<<2+"
"(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;\n");
break;
case BDT_ISO_FILE_READ:
filename2=FileNameAbs(filename);
DocPrint(doc,"bd->file_dsk_name=AStrNew(\"%s\");\n",filename2);
DocPrint(doc,"bd->drv_offset=19<<2+"
"(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;\n");
break;
case BDT_ATA:
case BDT_ATAPI:
if (type==BDT_ATAPI && !*base0_buf) {
DocPrint(doc,"GetBaseUnit(bd);\n"); //Only $LK,"::/Kernel/KCfg.HC"$
if (drv_let==boot_drv_let)
make_free=TRUE;
} else
DocPrint(doc,"bd->base0=%s;bd->base1=%s;\n",base0_buf,base1_buf);
if (type==BDT_ATA && _caller_is_prtdsk) {
"\nReformat WHOLE drive!";
whole_drv=YorN;
}
break;
}
DocPrint(doc,"BlkDevAdd(bd,%d,%d,%d);\n",prt_num,whole_drv,make_free);
if (_doc) //Called by $LK,"::/Kernel/KCfg.HC"$
cnt++;
else { //Called by $LK,"Mount",A="MN:Mount"$()
if ((cnt=ExeDoc(doc)) && whole_drv) {
if (_caller_is_prtdsk) {
res=drv_let;
PrtDsk(drv_let,1.0); //First mount whole drive.
} else
PrtDsk(drv_let);
}
DocDel(doc);
}
}
total+=cnt;
} while (cnt && !_caller_is_prtdsk ||
!total && _doc); //At least 1 if Called by $LK,"::/Kernel/KCfg.HC"$
Free(filename);
Free(filename2);
return res;
}
public U8 Mount(Bool caller_is_prtdsk=FALSE)
{//Mount drives. Called from $LK,"PrtDsk(Mount)",A="FF:::/Adam/ABlkDev/PrtDsk.HC,Mount("$.
return Mount2(0,NULL,caller_is_prtdsk);
}
public U0 Unmount(U8 drv_let=0)
{//Unmount drive(s).
BlkDevDel(Let2BlkDev(drv_let));
}
public U8 MountFile(U8 *filename)
{//Mount ISO.C file.
U8 *filename2=DftExt(filename,"ISO.C"),*filename3=FileNameAbs(filename2);
CDrv *dv=DrvMakeFreeSlot(DrvNextFreeLet('M')); //First $LK,"BDT_ISO_FILE_READ",A="MN:BDT_ISO_FILE_READ"$
CBlkDev *bd=BlkDevNextFreeSlot(dv->drv_let,BDT_ISO_FILE_READ);
bd->drv_offset=19<<2+(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;
bd->file_dsk_name=AStrNew(filename3);
BlkDevAdd(bd,,TRUE,TRUE);
Free(filename3);
Free(filename2);
return dv->drv_let;
}
+167
View File
@@ -0,0 +1,167 @@
#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically)"
#define ROUND_DRV_TO (63*255)
#define DRV_HEADER 63
class CPlannedDrv
{
CPlannedDrv *next,*last;
I64 size;
Bool pri;
};
public I64 PrtDsk(U8 drv_let=0,...)
{/*Partition the disk containing partition drv_let.
drv_let=0 means add new drive that is not already mounted.
>PrtDsk('C',0.5,0.25,0.25); //Make three. 50% C, 25% D, 25% E, round-up to blk.
*/
CBlkDev *bd;
CPlannedDrv head,*tmppp;
CMasterBoot mbr;
Bool pri=TRUE;
I64 ext_base,drv_let2,pri_cnt=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)
return 0;
'\n';
if (drv_let && !Let2BlkDev(drv_let,FALSE))
drv_let=0;
if (!drv_let && !(drv_let=Mount(TRUE)) ||
!(bd=Let2BlkDev(drv_let,FALSE)) || bd->type!=BDT_ATA)
return 0;
total=bd->max_blk+1;
QueInit(&head);
drv_let2=bd->first_drv_let;
remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO);
while (FloorU64(remaining,ROUND_DRV_TO)>=ROUND_DRV_TO) {
tmppp=MAlloc(sizeof(CPlannedDrv));
do {
"$$RED$$Partition %C$$FG$$\n",drv_let2;
tmppp->pri=FALSE;
if (pri) {
"Primary Partition";
if (argc>cur_arg || YorN) {
pri_cnt++;
tmppp->pri=TRUE;
if (pri_cnt==3)
pri=FALSE;
} else
pri=FALSE;
}
"\nBlocks Remaining:%d (0x%X)\n",
remaining-DRV_HEADER,remaining-DRV_HEADER;
if (argc>cur_arg)
tmppp->size=MinI64(CeilU64(MaxI64(remaining,DRV_HEADER),ROUND_DRV_TO),
CeilU64(argv[cur_arg++](F64)*total,ROUND_DRV_TO));
else
tmppp->size=CeilU64(GetI64("Size in Blocks :",
remaining-DRV_HEADER)+DRV_HEADER,ROUND_DRV_TO);
} while (!(ROUND_DRV_TO<=tmppp->size<=FloorU64(remaining,ROUND_DRV_TO)));
QueIns(tmppp,head.last);
remaining-=tmppp->size;
drv_let2++;
}
"\n\n!!! Repartition Drive !!!\n\n";
tmppp=head.next;
drv_let2=bd->first_drv_let;
while (tmppp!=&head) {
"Drive %C:%08X ",drv_let2,tmppp->size;
if (tmppp->pri)
"Primary\n";
else
"Logical\n";
tmppp=tmppp->next;
drv_let2++;
}
if (!argc && !AreYouSure)
goto pd_done;
remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO)-ROUND_DRV_TO;
tmppp=head.next;
MemSet(&mbr,0,BLK_SIZE);
mbr.signature=0xAA55;
offset=0;
for (i=0;i<pri_cnt;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=DRV_HEADER+offset;
mbr.p[i].size=tmppp->size-DRV_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;
}
ATAWriteBlks(bd,&mbr,0,1);
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=DRV_HEADER;
mbr.p[0].size=tmppp->size-DRV_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);
}
bd->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS);
BlkDevAdd(bd,,FALSE,TRUE);
for (i=bd->first_drv_let;i<drv_let2;i++)
Fmt(i,,FALSE);
pd_done:
while (head.next!=&head) {
tmppp=head.next;
QueRem(tmppp);
Free(tmppp);
}
return total;
}