SparrowOSTS_121127.ISO
This commit is contained in:
1 parent
0e9364ff4c
commit
e57428affb
1218 files changed
+247142
-165507
No files matched your search
@@ -0,0 +1,232 @@
|
||||
#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 NativeFSChkDskList(CDirEntry *tempm1,U8 *bits,U8 *bits2,I64 size,I64 bpc)
|
||||
{
|
||||
CDirEntry *tempm2;
|
||||
I64 i,j,errs=0;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub)
|
||||
errs+=NativeFSChkDskList(tempm1->sub,bits,bits2,size,bpc);
|
||||
}
|
||||
j=(tempm1->size+bpc-1)/bpc;
|
||||
for (i=0;i<j;i++) {
|
||||
if (i+tempm1->cluster>size) {
|
||||
PrintFErr("Invalid Cluster:%s Cluster:%X\n",tempm1->full_name,
|
||||
i+tempm1->cluster);
|
||||
errs++;
|
||||
break;
|
||||
}
|
||||
if (LBts(bits,i+tempm1->cluster)) {
|
||||
PrintFErr("Dbl Alloc:%s Cluster:%X\n",tempm1->full_name,
|
||||
i+tempm1->cluster);
|
||||
errs++;
|
||||
}
|
||||
if (!LBtr(bits2,i+tempm1->cluster)) {
|
||||
PrintFErr("UnAlloc:%s Cluster:%X\n",tempm1->full_name,
|
||||
i+tempm1->cluster);
|
||||
errs++;
|
||||
}
|
||||
}
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
I64 NativeFSChkDsk(U8 drv_let,Bool *_fix,Bool *_confirm)
|
||||
{
|
||||
I64 i,j,bpc,size,errs=0;
|
||||
CPrt *p=Drv2Prt(drv_let),*old_prt=Fs->cur_prt;
|
||||
U8 *files_find_mask=MSPrintF("%c:/*",Prt2Drv(p)),
|
||||
*old_dir=StrNew(Fs->cur_dir),
|
||||
*bits,*bits2;
|
||||
CDirEntry *ptr,*ptr2;
|
||||
|
||||
Drv(drv_let);
|
||||
"Scanning...\n";
|
||||
size=(p->size-(p->data-p->offset))/p->spc;
|
||||
bpc=p->spc<<BLK_SIZE_BITS;
|
||||
bits=CAlloc((size+7)>>3);
|
||||
bits2=CAlloc((size+7)>>3+BLK_SIZE);
|
||||
RBlks(p,bits2,p->map1,((size+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS);
|
||||
|
||||
//Get Root Dir size
|
||||
ptr2=MAlloc(bpc);
|
||||
RClusters(p,ptr2,p->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+p->root_cluster>size) {
|
||||
PrintFErr("Invalid Cluster: RootDir Cluster:%X\n",i+p->root_cluster);
|
||||
errs++;
|
||||
break;
|
||||
}
|
||||
if (LBts(bits,i+p->root_cluster)) {
|
||||
PrintFErr("Dbl Alloc: RootDir Cluster:%X\n",i+p->root_cluster);
|
||||
errs++;
|
||||
}
|
||||
if (!LBtr(bits2,i+p->root_cluster)) {
|
||||
PrintFErr("UnAlloc: RootDir Cluster:%X\n",i+p->root_cluster);
|
||||
errs++;
|
||||
}
|
||||
}
|
||||
|
||||
errs+=NativeFSChkDskList(FilesFind(files_find_mask,1<<FUf_RECURSE),bits,bits2,size,bpc);
|
||||
for (i=1;i<size;i++)
|
||||
if (Bt(bits2,i)) {
|
||||
PrintFWarn("Shouldn't Alloc Cluster:%0X\n",i);
|
||||
errs++;
|
||||
if (ChkDskConfirm(_fix,_confirm))
|
||||
NativeFSFreeClusters(p,i,1);
|
||||
}
|
||||
|
||||
Free(files_find_mask);
|
||||
Free(bits);
|
||||
Free(bits2);
|
||||
Drv(Prt2Drv(old_prt));
|
||||
Cd(old_dir);
|
||||
Free(old_dir);
|
||||
return errs;
|
||||
}
|
||||
|
||||
I64 FAT32ChkDskList(CPrt *p,CDirEntry *tempm1,U8 *bits,U32 *bits2,I64 size,I64 bpc)
|
||||
{
|
||||
CDirEntry *tempm2;
|
||||
I64 i,c,errs=0;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub)
|
||||
errs+=FAT32ChkDskList(p,tempm1->sub,bits,bits2,size,bpc);
|
||||
}
|
||||
i=0;
|
||||
c=tempm1->cluster;
|
||||
while (0<c<0x0FFFFFF8) {
|
||||
if (c>size) {
|
||||
PrintFErr("Invalid Cluster:%s Cluster:%X\n",tempm1->full_name,c);
|
||||
errs++;
|
||||
break;
|
||||
}
|
||||
if (LBts(bits,c)) {
|
||||
PrintFErr("Dbl Alloc:%s Cluster:%X\n",tempm1->full_name,c);
|
||||
errs++;
|
||||
}
|
||||
if (!bits2[c]) {
|
||||
PrintFErr("UnAlloc:%s Cluster:%X\n",tempm1->full_name,c);
|
||||
errs++;
|
||||
} else
|
||||
bits2[c]=0;
|
||||
c=ClusterNumNext(p,c);
|
||||
i++;
|
||||
}
|
||||
if (!(tempm1->attr & _ATTR_DIR)) {
|
||||
i*=bpc;
|
||||
if (tempm1->size>i) {
|
||||
PrintFErr("Allocated File Too Short:%s\n",tempm1->full_name);
|
||||
errs++;
|
||||
}
|
||||
if (i>tempm1->size+bpc-1) {
|
||||
PrintFWarn("Allocated File Too Long:%s\n",tempm1->full_name);
|
||||
errs++;
|
||||
}
|
||||
}
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
I64 FAT32ChkDsk(U8 drv_let,Bool *_fix,Bool *_confirm)
|
||||
{
|
||||
I64 i,bpc,size,c,errs=0;
|
||||
CPrt *p=Drv2Prt(drv_let),*old_prt=Fs->cur_prt;
|
||||
U8 *files_find_mask=MSPrintF("%c:/*",Prt2Drv(p)),
|
||||
*old_dir=StrNew(Fs->cur_dir),
|
||||
*bits;
|
||||
U32 *bits2;
|
||||
Drv(drv_let);
|
||||
"Scanning...\n";
|
||||
size=(p->size-(p->data-p->offset))/p->spc;
|
||||
bpc=p->spc<<BLK_SIZE_BITS;
|
||||
bits=CAlloc((size+7)>>3);
|
||||
bits2=CAlloc(size*4+BLK_SIZE);
|
||||
RBlks(p,bits2,p->map1,(size*4+BLK_SIZE-1)>>BLK_SIZE_BITS);
|
||||
|
||||
c=p->root_cluster;
|
||||
while (0<c<0x0FFFFFF8) {
|
||||
if (c>size) {
|
||||
PrintFErr("Invalid Cluster: RootDir Cluster:%X\n",c);
|
||||
errs++;
|
||||
break;
|
||||
}
|
||||
if (LBts(bits,c)) {
|
||||
PrintFErr("Dbl Alloc: RootDir Cluster:%X\n",c);
|
||||
errs++;
|
||||
}
|
||||
if (!bits2[c]) {
|
||||
PrintFErr("UnAlloc: RootDir Cluster:%X\n",c);
|
||||
errs++;
|
||||
} else
|
||||
bits2[c]=0;
|
||||
c=ClusterNumNext(p,c);
|
||||
}
|
||||
|
||||
errs+=FAT32ChkDskList(p,FilesFind(files_find_mask,1<<FUf_RECURSE),bits,bits2,size,bpc);
|
||||
|
||||
bits2[1]=0; //See $LK,"FAT32Fmt","MN:FAT32Fmt"$()
|
||||
for (i=1;i<size;i++)
|
||||
if (bits2[i]) {
|
||||
PrintFWarn("Shouldn't Alloc Cluster:%0X\n",i);
|
||||
errs++;
|
||||
if (ChkDskConfirm(_fix,_confirm))
|
||||
FAT32FreeClusters(p,i);
|
||||
}
|
||||
Free(files_find_mask);
|
||||
Free(bits);
|
||||
Free(bits2);
|
||||
Drv(Prt2Drv(old_prt));
|
||||
Cd(old_dir);
|
||||
Free(old_dir);
|
||||
return errs;
|
||||
}
|
||||
|
||||
public I64 ChkDsk(U8 drv_let=0,Bool fix=FALSE,Bool confirm=TRUE)
|
||||
{ //Check for allocation errors.
|
||||
I64 errs=0;
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
switch (p->type) {
|
||||
case PT_NATIVE:
|
||||
errs=NativeFSChkDsk(drv_let,&fix,&confirm);
|
||||
break;
|
||||
case PT_FAT32:
|
||||
errs=FAT32ChkDsk(drv_let,&fix,&confirm);
|
||||
break;
|
||||
default:
|
||||
PutDefineErr("ST_UNSUPPORTED_FILE_SYSTEM");
|
||||
}
|
||||
if (errs) {
|
||||
if (fix)
|
||||
"It might be a little better. ";
|
||||
"Copy files to another partition or CD-ROM, "
|
||||
"reformat, and copy back. "
|
||||
"Or, copy from a back-up.\n";
|
||||
}
|
||||
return errs;
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "Dsk2a"
|
||||
#include "Dsk2b"
|
||||
#include "DskCDDVD"
|
||||
#include "ChkDsk"
|
||||
#include "FileMgr"
|
||||
@@ -0,0 +1,426 @@
|
||||
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
|
||||
|
||||
public U8 *DBlk(I64 blk,Bool write=FALSE)
|
||||
{//Dump Disk Blk.
|
||||
//If you set write to TRUE, it will be written when you press <ESC>.
|
||||
//See $LK,"::/SparrowOS/Demo/Dsk/Raw.CPP.Z","FI:::/SparrowOS/Demo/Dsk/Raw.CPP.Z"$.
|
||||
U8 *buf=MAlloc(BLK_SIZE);
|
||||
|
||||
RBlks(Fs->cur_prt,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_prt,buf,blk,1);
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
public U8 *DCluster(I64 c,Bool write=FALSE,I64 num=0)
|
||||
{//Dump Disk Cluster.
|
||||
//If you set write to TRUE, it will be written when you press <ESC>.
|
||||
//See $LK,"::/SparrowOS/Demo/Dsk/Raw.CPP.Z","FI:::/SparrowOS/Demo/Dsk/Raw.CPP.Z"$.
|
||||
//Do $LK,"Dir","MN:Dir"$("*",TRUE); to get cluster numbers of files.
|
||||
U8 *buf=MAlloc(Fs->cur_prt->spc<<BLK_SIZE_BITS);
|
||||
c=ClusterNumNext(Fs->cur_prt,c,num);
|
||||
RClusters(Fs->cur_prt,buf,c,1);
|
||||
"Cluster:%X\n",c;
|
||||
DocD(buf,Fs->cur_prt->spc<<BLK_SIZE_BITS);
|
||||
if (write) {
|
||||
"Edit and press <ESC> to write or <SHIFT-ESC>\n";
|
||||
if (View) {
|
||||
"Write\n";
|
||||
WClusters(Fs->cur_prt,buf,c,1);
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
#help_index "File/Program Routines"
|
||||
|
||||
U0 OFFlatten(CDirEntry *tempm,CDirEntry **a,I64 *i)
|
||||
{
|
||||
CDirEntry *tempm1;
|
||||
while (tempm) {
|
||||
tempm1=tempm->next;
|
||||
if (tempm->attr&_ATTR_DIR) {
|
||||
OFFlatten(tempm->sub,a,i);
|
||||
CDirEntryDel(tempm);
|
||||
} else {
|
||||
a[*i]=tempm;
|
||||
*i=*i+1;
|
||||
}
|
||||
tempm=tempm1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public I64 CFileCnt(CDirEntry *tempm)
|
||||
{
|
||||
I64 cnt=0;
|
||||
while (tempm) {
|
||||
if (tempm->attr&_ATTR_DIR)
|
||||
cnt+=CFileCnt(tempm->sub);
|
||||
else
|
||||
cnt++;
|
||||
tempm=tempm->next;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
I64 OFCompare(CDirEntry *e1,CDirEntry *e2)
|
||||
{
|
||||
return e1->cluster-e2->cluster;
|
||||
}
|
||||
|
||||
public CDirEntry **FilesOrder(CDirEntry *tempm,I64 *_cnt=NULL)
|
||||
{ //See $LK,"::/SparrowOS/Demo/Dsk/OrderedIO.CPP.Z","FI:::/SparrowOS/Demo/Dsk/OrderedIO.CPP.Z"$.
|
||||
I64 cnt=CFileCnt(tempm),i=0;
|
||||
CDirEntry **a=MAlloc(sizeof(CDirEntry *)*cnt);
|
||||
OFFlatten(tempm,a,&i);
|
||||
QSortI64(a,cnt,&OFCompare);
|
||||
if (_cnt) *_cnt=cnt;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
|
||||
|
||||
public Bool Copy(U8 *src_files_find_mask,U8 *dst_files_find_mask=".")
|
||||
{
|
||||
Bool result=TRUE;
|
||||
CFileAccess *fa;
|
||||
CDirEntry *tempm,*tempm1;
|
||||
U8 *st;
|
||||
if (!(tempm=FilesFind(src_files_find_mask)))
|
||||
return FALSE;
|
||||
if (IsDir(dst_files_find_mask)) {
|
||||
fa=FileAccessNew(dst_files_find_mask,TRUE);
|
||||
if (fa) {
|
||||
while (tempm) {
|
||||
tempm1=tempm->next;
|
||||
if (!(tempm->attr & _ATTR_DIR)) {
|
||||
st=FileNameAbs(tempm->name);
|
||||
if (!CopySingle(tempm->full_name,st))
|
||||
result=FALSE;
|
||||
Free(st);
|
||||
}
|
||||
CDirEntryDel(tempm);
|
||||
tempm=tempm1;
|
||||
}
|
||||
FileAccessDel(fa);
|
||||
}
|
||||
return result;
|
||||
} else
|
||||
return CopySingle(src_files_find_mask,dst_files_find_mask);
|
||||
}
|
||||
|
||||
public Bool Move(U8 *f1,U8 *f2)
|
||||
{
|
||||
if (Copy(f1,f2)) {
|
||||
Del(f1);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
I64 PutCopyTree(CDirEntry *tempm,I64 src_dir_len,I64 dst_dir_len,U8 *dst_dir)
|
||||
{
|
||||
U8 *st;
|
||||
I64 result=1;
|
||||
while (tempm) {
|
||||
st=MAlloc(StrLen(tempm->full_name)+dst_dir_len+2);
|
||||
MemCpy(st,dst_dir,dst_dir_len);
|
||||
StrCpy(st+dst_dir_len,tempm->full_name+src_dir_len);
|
||||
if (tempm->attr & _ATTR_DIR) {
|
||||
MkDir(st);
|
||||
result+=PutCopyTree(tempm->sub,src_dir_len,dst_dir_len,dst_dir);
|
||||
} else
|
||||
if (CopySingle(tempm->full_name,st))
|
||||
result++;
|
||||
Free(st);
|
||||
tempm=tempm->next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public I64 CopyTree(U8 *src_files_find_mask,U8 *dst_files_find_mask)
|
||||
{ //returns count of copied files (not dirs)
|
||||
CFileAccess *fa;
|
||||
CDirEntry *tempm=NULL;
|
||||
I64 result=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);
|
||||
|
||||
fa=FileAccessNew(src_files_find_mask,TRUE);
|
||||
if (fa) {
|
||||
tempm=SysFilesFind(fa->mask,1<<FUf_RECURSE);
|
||||
st1=CurDir;
|
||||
FileAccessDel(fa);
|
||||
i1=StrLen(st1);
|
||||
if (i1==3) i1--;
|
||||
|
||||
fa=FileAccessNew(dst_files_find_mask,TRUE,TRUE);
|
||||
if (fa) {
|
||||
st2=CurDir;
|
||||
i2=StrLen(st2);
|
||||
if (i2==3) i2--;
|
||||
result=PutCopyTree(tempm,i1,i2,st2);
|
||||
FileAccessDel(fa);
|
||||
Free(st2);
|
||||
}
|
||||
CDirListDel(tempm);
|
||||
Free(st1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 DelTreeDirs(CDirEntry *tempm1)
|
||||
{
|
||||
CDirEntry *tempm2;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub)
|
||||
DelTreeDirs(tempm1->sub);
|
||||
SysDel(tempm1->full_name,TRUE);
|
||||
}
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
}
|
||||
|
||||
U0 DelTreeFiles(CDirEntry *tempm1)
|
||||
{
|
||||
CDirEntry *tempm2;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub)
|
||||
DelTreeFiles(tempm1->sub);
|
||||
} else
|
||||
SysDel(tempm1->full_name,FALSE);
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
}
|
||||
|
||||
public U0 DelTree(U8 *files_find_mask,U8 *fu_flags=NULL)
|
||||
{
|
||||
I64 fuf_flags=0;
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
if (IsDir(files_find_mask)) {
|
||||
DelTreeDirs(FilesFind(files_find_mask,fuf_flags));
|
||||
SysDel(files_find_mask,TRUE);
|
||||
SysDel(files_find_mask,FALSE);
|
||||
} else
|
||||
DelTreeFiles(FilesFind(files_find_mask,fuf_flags));
|
||||
}
|
||||
|
||||
U0 TouchFile(U8 *filename,U8 *attr,CDate ltdt=0) //Just one file
|
||||
{
|
||||
CPrt *p=Drv2Prt(*filename);
|
||||
CDirEntry de;
|
||||
U8 *cur_dir=StrNew(filename),
|
||||
buf[136];
|
||||
if (FileFind(filename,&de,FALSE,TRUE)) {
|
||||
if (!StrCmp(attr,"+?"))
|
||||
"%-32ts %s\n",filename,SPrintFFlags(buf,Define("ST_FILE_ATTRS"),de.attr);
|
||||
else {
|
||||
StrFirstRem(cur_dir,":");
|
||||
StrLastRem(cur_dir,"/");
|
||||
if (!*cur_dir)
|
||||
StrCpy(cur_dir,"/");
|
||||
GetFFlags(&de.attr,Define("ST_FILE_ATTRS"),attr);
|
||||
if (ltdt)
|
||||
de.datetime=ltdt;
|
||||
else
|
||||
de.datetime=GetCurTimeCDate;
|
||||
CDirNew(p,cur_dir,&de,FALSE);
|
||||
}
|
||||
} else PutDefineErr("ST_FILE_NOT_FOUND");
|
||||
}
|
||||
|
||||
U0 TouchList(CDirEntry *tempm1,U8 *attr,CDate ltdt=0)
|
||||
{
|
||||
CDirEntry *tempm2;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub) {
|
||||
"%S%s\n","ST_SCANNING_DIR",tempm1->full_name;
|
||||
TouchList(tempm1->sub,attr,ltdt);
|
||||
}
|
||||
} else
|
||||
TouchFile(tempm1->full_name,attr,ltdt);
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
}
|
||||
|
||||
public U0 Touch(U8 *files_find_mask,U8 *attr="+?",U8 *fu_flags=NULL,CDate ltdt=0)
|
||||
{
|
||||
//Attr "+?" =show
|
||||
// "+T" =resident
|
||||
I64 fuf_flags=0;
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
TouchList(FilesFind(files_find_mask,fuf_flags),attr,ltdt);
|
||||
}
|
||||
|
||||
I64 FFList(CDirEntry *tempm1)
|
||||
{
|
||||
I64 cnt=0;
|
||||
CDirEntry *tempm2;
|
||||
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
if (tempm1->sub)
|
||||
cnt+=FFList(tempm1->sub);
|
||||
} else {
|
||||
PutFileLink(tempm1->full_name);
|
||||
NewLine;
|
||||
cnt++;
|
||||
}
|
||||
CDirEntryDel(tempm1);
|
||||
tempm1=tempm2;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
public I64 FF(U8 *files_find_mask,U8 *fu_flags=NULL)
|
||||
//Files Find
|
||||
{
|
||||
I64 cnt=0,fuf_flags=0;
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
cnt+=FFList(FilesFind(files_find_mask,fuf_flags));
|
||||
return cnt;
|
||||
}
|
||||
|
||||
public U0 SetDrvTextAttr(U8 drv_let,U8 attr)
|
||||
{ //This is to color the border text according to the current drive
|
||||
CPrt *p;
|
||||
try {
|
||||
p=Drv2Prt(drv_let);
|
||||
p->text_attr=attr;
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
}
|
||||
|
||||
U0 PrintFDrvTextAttr(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
U8 fg=p->text_attr&0xF,bg=p->text_attr>>4;
|
||||
if (fg!=bg)
|
||||
"$$FG,%d$$$$BG,%d$$",fg,bg;
|
||||
}
|
||||
|
||||
I64 NativeFSUnusedDrvSpace(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
I64 result=0,i,l;
|
||||
U8 *bitmap;
|
||||
try {
|
||||
l=(p->size+p->spc-1)/p->spc;
|
||||
i=((l+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
bitmap=MAlloc(i<<BLK_SIZE_BITS);
|
||||
RBlks(p,bitmap,p->map1,i);
|
||||
for (i=0;i<l;i++)
|
||||
if (!Bt(bitmap,i))
|
||||
result++;
|
||||
Free(bitmap);
|
||||
} catch
|
||||
PrtUnlock(p);
|
||||
return result*BLK_SIZE*p->spc;
|
||||
}
|
||||
|
||||
I64 FAT32UnusedDrvSpace(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
I64 result=0,i,l;
|
||||
U32 *bitmap;
|
||||
try {
|
||||
l=(p->size+p->spc-1)/p->spc;
|
||||
i=(l*4+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
bitmap=MAlloc(i<<BLK_SIZE_BITS);
|
||||
RBlks(p,bitmap,p->map1,i);
|
||||
for (i=0;i<l;i++)
|
||||
if (!bitmap[i])
|
||||
result++;
|
||||
Free(bitmap);
|
||||
} catch
|
||||
PrtUnlock(p);
|
||||
return result*BLK_SIZE*p->spc;
|
||||
}
|
||||
|
||||
public I64 UnusedDrvSpace(U8 drv_let=0)
|
||||
{ //returns size in bytes
|
||||
CPrt *p=Drv2Prt(drv_let),*p_old=Fs->cur_prt;
|
||||
U8 *old_dir=StrNew(Fs->cur_dir);
|
||||
I64 result=0;
|
||||
Drv(drv_let);
|
||||
switch (p->type) {
|
||||
case PT_NATIVE:
|
||||
result=NativeFSUnusedDrvSpace(drv_let);
|
||||
break;
|
||||
case PT_FAT32:
|
||||
result=FAT32UnusedDrvSpace(drv_let);
|
||||
break;
|
||||
default:
|
||||
PutDefineErr("ST_UNSUPPORTED_FILE_SYSTEM");
|
||||
}
|
||||
Drv(Prt2Drv(p_old));
|
||||
Cd(old_dir);
|
||||
Free(old_dir);
|
||||
return result;
|
||||
}
|
||||
|
||||
#help_index "File/Program Routines"
|
||||
|
||||
I64 TreeSizeFiles(CDirEntry *tempm,I64 round_to)
|
||||
{
|
||||
I64 result=0,i;
|
||||
while (tempm) {
|
||||
if (round_to)
|
||||
i=CeilU64(tempm->size,round_to);
|
||||
else
|
||||
i=tempm->size;
|
||||
if (tempm->attr&_ATTR_DIR)
|
||||
i+=TreeSizeFiles(tempm->sub,round_to);
|
||||
tempm->user_data=i;
|
||||
result+=i;
|
||||
tempm=tempm->next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public I64 TreeSize(U8 *files_find_mask="/SparrowOS/*",U8 *fu_flags=NULL,I64 round_to=0)
|
||||
{
|
||||
//Does not include directory size of base directory, but
|
||||
//does include size of sub directories.
|
||||
I64 fuf_flags=0,result=0;
|
||||
CDirEntry *tempm1=NULL;
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
if (tempm1=FilesFind(files_find_mask,fuf_flags)) {
|
||||
result=TreeSizeFiles(tempm1,round_to);
|
||||
CDirListDel(tempm1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,549 @@
|
||||
#help_index "File/Program Routines/Utils"
|
||||
|
||||
I64 CDirTreeFlattenSize(CDirEntry *tempm)
|
||||
{
|
||||
I64 result=0;
|
||||
while (tempm) {
|
||||
result+=CDIR_SIZE+1;
|
||||
if (tempm->attr & _ATTR_DIR)
|
||||
result+=CDirTreeFlattenSize(tempm->sub);
|
||||
tempm=tempm->next;
|
||||
}
|
||||
return result+1;
|
||||
}
|
||||
|
||||
I64 CDirTreeFlattenFill(CDirEntry *tempm,U8 *dst)
|
||||
{
|
||||
I64 result=0,i;
|
||||
while (tempm) {
|
||||
*dst++=1;
|
||||
result++;
|
||||
i=CDIR_SIZE;
|
||||
MemCpy(dst,&tempm->start,i);
|
||||
dst+=i;
|
||||
result+=i;
|
||||
if (tempm->attr & _ATTR_DIR) {
|
||||
i=CDirTreeFlattenFill(tempm->sub,dst);
|
||||
dst+=i;
|
||||
result+=i;
|
||||
}
|
||||
tempm=tempm->next;
|
||||
}
|
||||
*dst=0;
|
||||
return result+1;
|
||||
}
|
||||
|
||||
public U8 *CDirTreeFlatten(CDirEntry *tempm,I64 *_size=NULL)
|
||||
{
|
||||
I64 size=CDirTreeFlattenSize(tempm);
|
||||
U8 *buf=MAlloc(size);
|
||||
CDirTreeFlattenFill(tempm,buf);
|
||||
if (_size) *_size=size;
|
||||
return buf;
|
||||
}
|
||||
|
||||
U8 *CDirTreeDoUnflatten(U8 *src,CDirEntry **tempm)
|
||||
{
|
||||
I64 i;
|
||||
CDirEntry *tempm1;
|
||||
if (*src++) {
|
||||
tempm1=CAlloc(sizeof(CDirEntry));
|
||||
*tempm=tempm1;
|
||||
i=CDIR_SIZE;
|
||||
MemCpy(&tempm1->start,src,i);
|
||||
src+=i;
|
||||
if (tempm1->attr & _ATTR_DIR)
|
||||
src=CDirTreeDoUnflatten(src,&tempm1->sub);
|
||||
src=CDirTreeDoUnflatten(src,&tempm1->next);
|
||||
} else
|
||||
*tempm=NULL;
|
||||
return src;
|
||||
}
|
||||
|
||||
public CDirEntry *CDirTreeUnflatten(U8 *src)
|
||||
{
|
||||
CDirEntry *tempm=NULL;
|
||||
CDirTreeDoUnflatten(src,&tempm);
|
||||
return tempm;
|
||||
}
|
||||
|
||||
#help_index "Install;File/Install Related"
|
||||
#help_file "::/SparrowOS/Doc/Install"
|
||||
|
||||
#define ROUND_PRT_TO (63*255)
|
||||
#define PRT_HEADER 63
|
||||
|
||||
class CPlannedPrt
|
||||
{
|
||||
CPlannedPrt *next,*last;
|
||||
I64 size;
|
||||
Bool pri;
|
||||
};
|
||||
|
||||
//This is available to assist in writing scripts.
|
||||
I64 prt_dsk_dsk_size;
|
||||
|
||||
public U0 PrtDsk(U8 drv_let=0)
|
||||
//Partition Disk containing partition drv_let.
|
||||
//or drv_let=0 means add new drv that is not already mounted.
|
||||
{
|
||||
CBlkDev *bdev;
|
||||
CPlannedPrt root,*temppp;
|
||||
CMasterBoot mbr;
|
||||
Bool pri=TRUE;
|
||||
I64 ext_base,num_prt,pri_cnt=0,
|
||||
i,start_offset,offset,remaining;
|
||||
"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,\"MasterBootZero\",\"MN:MasterBootZero\"$$()\n\n\n"
|
||||
"Continue";
|
||||
if (!YorN) return;
|
||||
|
||||
if (drv_let)
|
||||
try
|
||||
Drv2BlkDev(drv_let);
|
||||
catch {
|
||||
drv_let=0;
|
||||
Fs->catch_except=TRUE;
|
||||
}
|
||||
|
||||
if (!drv_let) {
|
||||
Mount(TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
bdev=Drv2BlkDev(drv_let);
|
||||
if (!bdev || bdev->type!=BDT_ATA)
|
||||
return;
|
||||
|
||||
prt_dsk_dsk_size=bdev->max_blk+1;
|
||||
|
||||
QueInit(&root);
|
||||
|
||||
num_prt=bdev->drv_let_base;
|
||||
remaining=FloorU64(bdev->max_blk+1,ROUND_PRT_TO);
|
||||
while (FloorU64(remaining,ROUND_PRT_TO)>=ROUND_PRT_TO) {
|
||||
temppp=MAlloc(sizeof(CPlannedPrt));
|
||||
do {
|
||||
"$$FG,RED$$Partition %C$$FG$$\n",num_prt;
|
||||
temppp->pri=FALSE;
|
||||
if (pri) {
|
||||
"Primary Partition";
|
||||
if (YorN) {
|
||||
pri_cnt++;
|
||||
temppp->pri=TRUE;
|
||||
if (pri_cnt==3)
|
||||
pri=FALSE;
|
||||
} else
|
||||
pri=FALSE;
|
||||
}
|
||||
"Blocks Remaining:%d (0x%X)\n",
|
||||
remaining-PRT_HEADER,remaining-PRT_HEADER;
|
||||
temppp->size=CeilU64(PmtI64("Size in Blocks :",
|
||||
remaining-PRT_HEADER)+PRT_HEADER,ROUND_PRT_TO);
|
||||
} while (!(ROUND_PRT_TO<=temppp->size<=FloorU64(remaining,ROUND_PRT_TO)));
|
||||
QueIns(temppp,root.last);
|
||||
remaining-=temppp->size;
|
||||
num_prt++;
|
||||
}
|
||||
|
||||
"\n\n!!! Repartition Drive !!!\n\n";
|
||||
temppp=root.next;
|
||||
num_prt=bdev->drv_let_base;
|
||||
while (temppp!=&root) {
|
||||
"Drive %C:%08X %s\n",num_prt,temppp->size,
|
||||
temppp->pri ? "Primary":"Logical";
|
||||
temppp=temppp->next;
|
||||
num_prt++;
|
||||
}
|
||||
if (!AreYouSure)
|
||||
goto pd_done;
|
||||
|
||||
remaining=FloorU64(bdev->max_blk+1,ROUND_PRT_TO)-ROUND_PRT_TO;
|
||||
temppp=root.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 to MBR_PT_NATIVE
|
||||
mbr.p[i].end_head=0xFE;
|
||||
mbr.p[i].end_cyl=0xFFFF;
|
||||
mbr.p[i].offset=PRT_HEADER+offset;
|
||||
mbr.p[i].size=temppp->size-PRT_HEADER;
|
||||
offset+=temppp->size;
|
||||
remaining-=temppp->size;
|
||||
temppp=temppp->next;
|
||||
}
|
||||
if (!i) i++;
|
||||
if (temppp!=&root) {
|
||||
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(bdev,&mbr,0,1);
|
||||
|
||||
while (temppp!=&root) {
|
||||
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 to MBR_PT_NATIVE
|
||||
mbr.p[0].end_head=0xFE;
|
||||
mbr.p[0].end_cyl=0xFFFF;
|
||||
mbr.p[0].offset=PRT_HEADER;
|
||||
mbr.p[0].size=temppp->size-PRT_HEADER;
|
||||
offset+=temppp->size;
|
||||
temppp=temppp->next;
|
||||
if (temppp!=&root) {
|
||||
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=temppp->size;
|
||||
}
|
||||
ATAWriteBlks(bdev,&mbr,start_offset,1);
|
||||
}
|
||||
|
||||
bdev->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS);
|
||||
BlkDevAdd(bdev,FALSE);
|
||||
for (i=bdev->drv_let_base;i<num_prt;i++)
|
||||
Fmt(i,TRUE,FALSE);
|
||||
|
||||
pd_done:
|
||||
while (root.next!=&root) {
|
||||
temppp=root.next;
|
||||
QueRem(temppp);
|
||||
Free(temppp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#help_index "Info;File/Cmd Line (Typically);Cmd Line (Typically)"
|
||||
|
||||
U0 NativeFSDrvView(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
I64 lohi,c1,i,x,y,l,s;
|
||||
U8 *bitmap;
|
||||
CDC *dc=DCAlias;
|
||||
|
||||
l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
|
||||
s=(p->size+p->spc-1)/p->spc;
|
||||
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
WinMax;
|
||||
DocCursor;
|
||||
DocClear;
|
||||
DCFill;
|
||||
try {
|
||||
i=((s+7)>>3+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
bitmap=MAlloc(i<<BLK_SIZE_BITS);
|
||||
RBlks(p,bitmap,p->map1,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^COLOR_TRANSPARENT;
|
||||
else
|
||||
dc->color=ROP_XOR+WHITE^COLOR_TRANSPARENT;
|
||||
GrPlot(dc,x,y);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Free(bitmap);
|
||||
} catch
|
||||
PrtUnlock(p);
|
||||
GetChar;
|
||||
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
U0 FAT32DrvView(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
I64 lohi,c1,i,x,y,l,s;
|
||||
U32 *bitmap;
|
||||
CDC *dc=DCAlias;
|
||||
l=(GR_HEIGHT-3*FONT_HEIGHT)*(GR_WIDTH-FONT_WIDTH<<1),
|
||||
s=(p->size+p->spc-1)/p->spc;
|
||||
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
WinMax;
|
||||
DocCursor;
|
||||
DocClear;
|
||||
DCFill;
|
||||
try {
|
||||
i=(s*4+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
bitmap=MAlloc(i<<BLK_SIZE_BITS);
|
||||
RBlks(p,bitmap,p->map1,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^COLOR_TRANSPARENT;
|
||||
else
|
||||
dc->color=ROP_XOR+WHITE^COLOR_TRANSPARENT;
|
||||
GrPlot(dc,x,y);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Free(bitmap);
|
||||
} catch
|
||||
PrtUnlock(p);
|
||||
GetChar;
|
||||
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
public U0 DrvView(U8 drv_let=0)
|
||||
{
|
||||
CPrt *p=Drv2Prt(drv_let),*p_old=Fs->cur_prt;
|
||||
Drv(drv_let);
|
||||
switch (p->type) {
|
||||
case PT_NATIVE:
|
||||
NativeFSDrvView(drv_let);
|
||||
break;
|
||||
case PT_FAT32:
|
||||
FAT32DrvView(drv_let);
|
||||
break;
|
||||
default:
|
||||
PutDefineErr("ST_UNSUPPORTED_FILE_SYSTEM");
|
||||
}
|
||||
Drv(Prt2Drv(p_old));
|
||||
}
|
||||
|
||||
public U0 DskView(U8 drv_let=0)
|
||||
{
|
||||
I64 i,j,
|
||||
h=Fs->win_pixel_width,
|
||||
v=Fs->win_pixel_height,
|
||||
radius;
|
||||
CPrt *p;
|
||||
CBlkDev *bdev=Drv2BlkDevFwded(drv_let);
|
||||
CDC *dc=DCAlias;
|
||||
F64 sect_start,sect_end;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
DocCursor;
|
||||
DocClear;
|
||||
DCFill;
|
||||
if (h<v)
|
||||
radius=0.4*h;
|
||||
else
|
||||
radius=0.4*v;
|
||||
dc->color=ROP_EQU+BLACK;
|
||||
GrCircle(dc,h>>1,v>>1,radius);
|
||||
|
||||
j=1;
|
||||
for (i=0;i<NUM_PRTS;i++) {
|
||||
p=&sys_prts[i];
|
||||
if (bdev==p->bdev && p->type) {
|
||||
sect_start=-(p->offset*2*ã/(bdev->max_blk+1));
|
||||
sect_end =-((p->offset+p->size)*2*ã/(bdev->max_blk+1));
|
||||
dc->color=ROP_EQU+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));
|
||||
|
||||
dc->color=ROP_EQU+j;
|
||||
GrPrintF(dc,0,v-FONT_HEIGHT*j,"%C %-8Z",Prt2Drv(p),
|
||||
p->type.u16[0],"ST_PRT_TYPES");
|
||||
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(NULL,FALSE);
|
||||
SettingsPop;
|
||||
DCFill;
|
||||
DCDel(dc);
|
||||
}
|
||||
|
||||
#help_index "Info;File/Cmd Line (Typically);Cmd Line (Typically);File/Install Related;Install"
|
||||
public U0 BlkDevRep()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<num_blkdevs;i++)
|
||||
ClassRep("CBlkDev",&sys_blkdevs[i]);
|
||||
}
|
||||
|
||||
#help_index "Install;File/Install Related"
|
||||
#define SC_BLK_CNT 2048
|
||||
public I64 NonNativeScan(I64 drv_let,U32 signature)
|
||||
{
|
||||
// See $LK,"::/SparrowOS/Doc/TSZ.TXT.Z","FI:::/SparrowOS/Doc/TSZ.TXT.Z"$
|
||||
U8 *buf=CAlloc(BLK_SIZE*SC_BLK_CNT),*b;
|
||||
U32 *d;
|
||||
CBlkDev *bdev=Drv2BlkDev(drv_let);
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
I64 *qq,blk=p->offset,result=0,start=0,i,j,n,to_go,size,
|
||||
contiguous=0,new_drv_let;
|
||||
Bool good,proceed=FALSE;
|
||||
try {
|
||||
while (!result) {
|
||||
'-';
|
||||
n=p->size+p->offset-blk;
|
||||
if (n>SC_BLK_CNT)
|
||||
n=SC_BLK_CNT;
|
||||
if (!n)
|
||||
break;
|
||||
RBlks(p,buf,blk,1);
|
||||
d=buf;
|
||||
qq=d;
|
||||
if (d[127]==signature) {
|
||||
b=d;
|
||||
good=TRUE;
|
||||
for (j=16;j<BLK_SIZE-4;j++)
|
||||
if (b[j]!=j.u8[0]) {
|
||||
good=FALSE;
|
||||
break;
|
||||
}
|
||||
if (good) {
|
||||
result=blk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
blk+=n;
|
||||
}
|
||||
if (result) {
|
||||
blk=result-(SC_BLK_CNT-1);
|
||||
if (blk<0) blk=0;
|
||||
result=0;
|
||||
n=p->size+p->offset-blk;
|
||||
if (n>SC_BLK_CNT)
|
||||
n=SC_BLK_CNT;
|
||||
RBlks(p,buf,blk,n);
|
||||
for (i=0;i<n;i++) {
|
||||
d=buf+BLK_SIZE*i;
|
||||
qq=d;
|
||||
if (d[127]==signature && !qq[0]) {
|
||||
b=d;
|
||||
good=TRUE;
|
||||
for (j=16;j<BLK_SIZE-4;j++)
|
||||
if (b[j]!=j.u8[0]) {
|
||||
good=FALSE;
|
||||
break;
|
||||
}
|
||||
if (good) {
|
||||
result=blk+i;
|
||||
size=qq[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
start=result;
|
||||
"\nStart :0x%X Size:0x%X\n",result,size;
|
||||
to_go=size;
|
||||
blk=result;
|
||||
while (to_go && result) {
|
||||
'+';
|
||||
n=to_go;
|
||||
if (n>SC_BLK_CNT)
|
||||
n=SC_BLK_CNT;
|
||||
RBlks(p,buf,blk,n);
|
||||
for (i=0;i<n;i++) {
|
||||
d=buf+BLK_SIZE*i;
|
||||
qq=d;
|
||||
if (d[127]==signature && qq[0]==blk-result+i &&
|
||||
qq[1]==size) {
|
||||
b=d;
|
||||
for (j=16;j<BLK_SIZE-4;j++)
|
||||
if (b[j]!=j.u8[0]) {
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
contiguous++;
|
||||
else
|
||||
break;
|
||||
} else {
|
||||
result=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
to_go-=n;
|
||||
blk+=n;
|
||||
}
|
||||
}
|
||||
"Start: 0x%X\n",result;
|
||||
if (result) {
|
||||
"\nSuccess\n";
|
||||
proceed=TRUE;
|
||||
} else {
|
||||
"\nFailed, but found 0x%X contiguous.\n",contiguous;
|
||||
if (contiguous) {
|
||||
"Proceed Anyway ";
|
||||
proceed=YorN;
|
||||
}
|
||||
}
|
||||
} catch
|
||||
Fs->catch_except=TRUE;
|
||||
|
||||
Cd("HOME");
|
||||
Free(buf);
|
||||
|
||||
if (proceed) {
|
||||
"New Drive Letter:";
|
||||
new_drv_let=ToUpper(GetChar);
|
||||
NewLine;
|
||||
bdev=&sys_blkdevs[num_blkdevs++];
|
||||
bdev->drv_let_base=new_drv_let;
|
||||
bdev->blk_size=BLK_SIZE;
|
||||
bdev->min_blk=start;
|
||||
bdev->max_blk=start+contiguous-1;
|
||||
bdev->non_native_drv=drv_let;
|
||||
bdev->non_native_offset=start;
|
||||
bdev->type=BDT_NON_NATIVE_FILE;
|
||||
bdev->flags=BDF_FMT;
|
||||
if (!BlkDevAdd(bdev,FALSE))
|
||||
PutDefine("ST_FAILED");
|
||||
Drv(new_drv_let);
|
||||
"File Blk: 0x%X\n",start;
|
||||
result=start;
|
||||
} else
|
||||
result=0;
|
||||
return result;
|
||||
}
|
||||
#help_index ""
|
||||
@@ -0,0 +1,598 @@
|
||||
#help_index "File/CD DVD"
|
||||
|
||||
U0 FillU16Palindrome(CPalindromeU16 *dst,U16 w)
|
||||
{
|
||||
dst->big=EndianU16(w);
|
||||
dst->little=w;
|
||||
}
|
||||
|
||||
U0 FillU32Palindrome(CPalindromeU32 *dst,I64 d)
|
||||
{
|
||||
dst->big=EndianU32(d);
|
||||
dst->little=d;
|
||||
}
|
||||
|
||||
|
||||
class CCCDUserData //Create CD
|
||||
{
|
||||
I64 loc,path_entry_num,
|
||||
short_dir_blks,long_dir_blks;
|
||||
};
|
||||
|
||||
I64 CDFileCreate2(CFile *out_file,CDirEntry *tempm,
|
||||
CISO1DirEntry *tempi,CISO1DirEntry *tempi2,
|
||||
I64 *_cur_blk,
|
||||
CDirEntry *parent,Bool write)
|
||||
{
|
||||
CCCDUserData *tempc;
|
||||
CDirEntry *tempm1,*tempm2;
|
||||
CFile *in_file;
|
||||
U8 *buf=MAlloc(CD_BLK_SIZE),*ptr1,*ptr2;
|
||||
CISO1DirEntry *dir_blk_buf =CAlloc(CD_BLK_SIZE*128),
|
||||
*de =dir_blk_buf, *de1,
|
||||
*dir_blk_buf2=CAlloc(CD_BLK_SIZE*128),
|
||||
*de2=dir_blk_buf2,*de12;
|
||||
I64 i,n;
|
||||
|
||||
tempc=parent->user_data;
|
||||
|
||||
de->len=sizeof(CISO1DirEntry)-1;
|
||||
de->ext_attr_len=0;
|
||||
FillU16Palindrome(&de->vol_seq_num,1);
|
||||
CDate2ISO1(&de->date,tempm->datetime);
|
||||
de->flags=ISO1_ATTR_DIR;
|
||||
de->name_len=1;
|
||||
de->name=0;
|
||||
de->len+=de->name_len;
|
||||
de(U8 *)+=de->len;
|
||||
|
||||
de->len=sizeof(CISO1DirEntry)-1;
|
||||
de->ext_attr_len=0;
|
||||
FillU32Palindrome(&de->loc,tempc->loc);
|
||||
FillU32Palindrome(&de->size,tempc->short_dir_blks*CD_BLK_SIZE);
|
||||
FillU16Palindrome(&de->vol_seq_num,1);
|
||||
CDate2ISO1(&de->date,parent->datetime);
|
||||
de->flags=ISO1_ATTR_DIR;
|
||||
de->name_len=1;
|
||||
de->name=1;
|
||||
de->len+=de->name_len;
|
||||
de(U8 *)+=de->len;
|
||||
|
||||
de2->len=sizeof(CISO1DirEntry)-1;
|
||||
de2->ext_attr_len=0;
|
||||
FillU16Palindrome(&de2->vol_seq_num,1);
|
||||
CDate2ISO1(&de2->date,tempm->datetime);
|
||||
de2->flags=ISO1_ATTR_DIR;
|
||||
de2->name_len=1;
|
||||
de2->name=0;
|
||||
de2->len=de2->len+de2->name_len;
|
||||
de2(U8 *)+=de2->len;
|
||||
|
||||
de2->len=sizeof(CISO1DirEntry)-1;
|
||||
de2->ext_attr_len=0;
|
||||
FillU32Palindrome(&de2->loc,tempc->loc+tempc->short_dir_blks);
|
||||
FillU32Palindrome(&de2->size,tempc->long_dir_blks*CD_BLK_SIZE);
|
||||
FillU16Palindrome(&de2->vol_seq_num,1);
|
||||
CDate2ISO1(&de2->date,parent->datetime);
|
||||
de2->flags=ISO1_ATTR_DIR;
|
||||
de2->name_len=1;
|
||||
de2->name=1;
|
||||
de2->len+=de2->name_len;
|
||||
de2(U8 *)+=de2->len;
|
||||
|
||||
tempm1=tempm->sub;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (!write) tempm1->user_data=CAlloc(sizeof(CCCDUserData));
|
||||
de1=de;
|
||||
de12=de2;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
n=CDFileCreate2(out_file,tempm1,de,de2,_cur_blk,tempm,write);
|
||||
de(U8 *)+=sizeof(CISO1DirEntry)-1+n;
|
||||
de2(U8 *)+=sizeof(CISO1DirEntry)-1+n<<1;
|
||||
} else {
|
||||
tempc=tempm1->user_data;
|
||||
de->len=sizeof(CISO1DirEntry)-1;
|
||||
de->ext_attr_len=0;
|
||||
FillU32Palindrome(&de->loc,*_cur_blk);
|
||||
tempc->loc=*_cur_blk;
|
||||
if (write)
|
||||
"%X:%s\n",*_cur_blk,tempm1->full_name;
|
||||
FillU32Palindrome(&de->size,tempm1->size);
|
||||
FillU16Palindrome(&de->vol_seq_num,1);
|
||||
CDate2ISO1(&de->date,tempm1->datetime);
|
||||
de->flags=0;
|
||||
de->name_len=StrLen(tempm1->name);
|
||||
StrCpy(&de->name,tempm1->name);
|
||||
de->len=de->len+de->name_len;
|
||||
de(U8 *)+=de->len;
|
||||
|
||||
de2->len=sizeof(CISO1DirEntry)-1;
|
||||
de2->ext_attr_len=0;
|
||||
FillU32Palindrome(&de2->loc,*_cur_blk);
|
||||
FillU32Palindrome(&de2->size,tempm1->size);
|
||||
FillU16Palindrome(&de2->vol_seq_num,1);
|
||||
CDate2ISO1(&de2->date,tempm1->datetime);
|
||||
de2->flags=0;
|
||||
de2->name_len=StrLen(tempm1->name)<<1;
|
||||
ptr1=&de2->name;
|
||||
ptr2=&tempm1->name;
|
||||
for (i=0;i<de2->name_len;i=i+2) {
|
||||
ptr1++;
|
||||
*ptr1++=*ptr2++;
|
||||
}
|
||||
de2->len+=de2->name_len;
|
||||
de2(U8 *)+=de2->len;
|
||||
|
||||
in_file=FOpen(tempm1->full_name,"r");
|
||||
for (i=0;i<(FSize(in_file)+CD_BLK_SIZE-1)/CD_BLK_SIZE;i++) {
|
||||
n=4;
|
||||
if ((i+1)<<2>(FSize(in_file)+BLK_SIZE-1)>>BLK_SIZE_BITS) {
|
||||
n=(FSize(in_file)+BLK_SIZE-1)>>BLK_SIZE_BITS&3;
|
||||
MemSet(buf,0,CD_BLK_SIZE);
|
||||
}
|
||||
if (write) {
|
||||
FRBlks(in_file,buf,i<<2,n);
|
||||
FWBlks(out_file,buf,*_cur_blk<<2,n);
|
||||
}
|
||||
*_cur_blk+=1;
|
||||
}
|
||||
FClose(in_file);
|
||||
}
|
||||
if ((de1(U8 *)-dir_blk_buf(U8 *))/CD_BLK_SIZE!=
|
||||
(de(U8 *) -dir_blk_buf(U8 *))/CD_BLK_SIZE) {
|
||||
i=de1->len;
|
||||
MemCpy(buf,de1,i);
|
||||
MemSet(de1,0,i);
|
||||
de=dir_blk_buf(U8 *)+(de(U8 *)-dir_blk_buf(U8 *))/CD_BLK_SIZE*CD_BLK_SIZE;
|
||||
MemCpy(de,buf,i);
|
||||
de(U8 *)+=i;
|
||||
}
|
||||
if ((de12(U8 *)-dir_blk_buf2(U8 *))/CD_BLK_SIZE!=
|
||||
(de2(U8 *) -dir_blk_buf2(U8 *))/CD_BLK_SIZE) {
|
||||
i=de12->len;
|
||||
MemCpy(buf,de12,i);
|
||||
MemSet(de12,0,i);
|
||||
de2(U8 *)=dir_blk_buf2(U8 *)+(de2(U8 *)-dir_blk_buf2(U8 *))/CD_BLK_SIZE*CD_BLK_SIZE;
|
||||
MemCpy(de2,buf,i);
|
||||
de2(U8 *)+=i;
|
||||
}
|
||||
tempm1=tempm2;
|
||||
}
|
||||
|
||||
tempc=tempm->user_data;
|
||||
|
||||
tempi->len=sizeof(CISO1DirEntry)-1;
|
||||
tempi->ext_attr_len=0;
|
||||
tempi->flags=ISO1_ATTR_DIR;
|
||||
if (!tempm->name[0]) {
|
||||
tempi->name_len=1;
|
||||
tempi->name=1;
|
||||
} else {
|
||||
tempi->name_len=StrLen(tempm->name);
|
||||
StrCpy(&tempi->name,tempm->name);
|
||||
}
|
||||
tempi->len+=tempi->name_len;
|
||||
|
||||
n=de(U8 *)+1-dir_blk_buf(U8 *);
|
||||
n=(n+CD_BLK_SIZE-1)/CD_BLK_SIZE;
|
||||
FillU32Palindrome(&tempi->size,n*CD_BLK_SIZE);
|
||||
FillU32Palindrome(&tempi->loc,*_cur_blk);
|
||||
tempc->short_dir_blks=n;
|
||||
tempc->loc=*_cur_blk;
|
||||
FillU32Palindrome(&dir_blk_buf->size,n*CD_BLK_SIZE);
|
||||
FillU32Palindrome(&dir_blk_buf->loc,*_cur_blk);
|
||||
FillU16Palindrome(&tempi->vol_seq_num,1);
|
||||
CDate2ISO1(&tempi->date,tempm->datetime);
|
||||
if (write)
|
||||
"%X:%s\n",*_cur_blk,tempm->full_name;
|
||||
if (write)
|
||||
FWBlks(out_file,dir_blk_buf,*_cur_blk<<2,n<<2);
|
||||
*_cur_blk+=n;
|
||||
|
||||
tempi2->len=sizeof(CISO1DirEntry)-1;
|
||||
tempi2->ext_attr_len=0;
|
||||
tempi2->flags=ISO1_ATTR_DIR;
|
||||
if (!tempm->name[0]) {
|
||||
tempi2->name_len=1;
|
||||
tempi->name=1;
|
||||
} else {
|
||||
tempi2->name_len=StrLen(tempm->name)<<1;
|
||||
ptr1=&tempi2->name;
|
||||
ptr2=&tempm->name;
|
||||
for (i=0;i<tempi2->name_len;i=i+2) {
|
||||
ptr1++;
|
||||
*ptr1++=*ptr2++;
|
||||
}
|
||||
}
|
||||
tempi2->len+=tempi2->name_len;
|
||||
n=de2(U8 *)+1-dir_blk_buf2(U8 *);
|
||||
n=(n+CD_BLK_SIZE-1)/CD_BLK_SIZE;
|
||||
FillU32Palindrome(&tempi2->size,n*CD_BLK_SIZE);
|
||||
FillU32Palindrome(&tempi2->loc,*_cur_blk);
|
||||
tempc->long_dir_blks=n;
|
||||
FillU32Palindrome(&dir_blk_buf2->size,n*CD_BLK_SIZE);
|
||||
FillU32Palindrome(&dir_blk_buf2->loc,*_cur_blk);
|
||||
FillU16Palindrome(&tempi2->vol_seq_num,1);
|
||||
CDate2ISO1(&tempi2->date,tempm->datetime);
|
||||
if (write)
|
||||
"%X:%s\n",*_cur_blk,tempm->full_name;
|
||||
if (write)
|
||||
FWBlks(out_file,dir_blk_buf2,*_cur_blk<<2,n<<2);
|
||||
*_cur_blk+=n;
|
||||
|
||||
Free(dir_blk_buf);
|
||||
Free(dir_blk_buf2);
|
||||
Free(buf);
|
||||
return tempi->name_len;
|
||||
}
|
||||
|
||||
I64 CDTableLen(CDirEntry *tempm,I64 *size1,I64 *size2,I64 cur_depth)
|
||||
//returns depth
|
||||
{
|
||||
CDirEntry *tempm1=tempm->sub;
|
||||
I64 max_depth=cur_depth,i;
|
||||
while (tempm1) {
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
*size1+=sizeof(CISO1PathEntry)-2+ (StrLen(tempm1->name)+1)&-0x2;
|
||||
*size2+=sizeof(CISO1PathEntry)-2+StrLen(tempm1->name)<<1;
|
||||
i=CDTableLen(tempm1,size1,size2,cur_depth+1);
|
||||
if (i>max_depth) max_depth=i;
|
||||
}
|
||||
tempm1=tempm1->next;
|
||||
}
|
||||
return max_depth;
|
||||
}
|
||||
|
||||
U0 CDFillPathTable(CDirEntry *tempm,
|
||||
CISO1PathEntry **_itabbuf,CISO1PathEntry **_itabbuf2,
|
||||
I64 parent_entry_num,Bool big_endian,I64 *first_free,I64 cur_level,I64 output_level)
|
||||
{
|
||||
U8 *ptr1,*ptr2;
|
||||
I64 i;
|
||||
CISO1PathEntry *tabbuf =*_itabbuf,
|
||||
*tabbuf2=*_itabbuf2;
|
||||
CDirEntry *tempm1=tempm->sub,*tempm2;
|
||||
CCCDUserData *tempc;
|
||||
|
||||
if (cur_level==output_level) {
|
||||
while (tempm1) {
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
tempc=tempm1->user_data;
|
||||
tempc->path_entry_num=*first_free;
|
||||
tabbuf->name_len=StrLen(tempm1->name);
|
||||
if (big_endian) {
|
||||
tabbuf->blk=EndianU32(tempc->loc);
|
||||
tabbuf->parent_entry_num=EndianU16(parent_entry_num);
|
||||
} else {
|
||||
tabbuf->blk=tempc->loc;
|
||||
tabbuf->parent_entry_num=parent_entry_num;
|
||||
}
|
||||
StrCpy(&tabbuf->name,tempm1->name);
|
||||
|
||||
tabbuf(U8 *)+=sizeof(CISO1PathEntry)-2+
|
||||
(StrLen(tempm1->name)+1) & -0x2;
|
||||
|
||||
tabbuf2->name_len=StrLen(tempm1->name)<<1;
|
||||
if (big_endian) {
|
||||
tabbuf2->blk=EndianU32(tempc->loc+tempc->short_dir_blks);
|
||||
tabbuf2->parent_entry_num=EndianU16(parent_entry_num);
|
||||
} else {
|
||||
tabbuf2->blk=tempc->loc+tempc->short_dir_blks;
|
||||
tabbuf2->parent_entry_num=parent_entry_num;
|
||||
}
|
||||
ptr1=&tabbuf2->name;
|
||||
ptr2=&tempm1->name;
|
||||
for (i=0;i<tabbuf2->name_len;i=i+2) {
|
||||
ptr1++;
|
||||
*ptr1++=*ptr2++;
|
||||
}
|
||||
tabbuf2(U8 *)+=sizeof(CISO1PathEntry)-2+
|
||||
StrLen(tempm1->name)<<1;
|
||||
*first_free+=1;
|
||||
}
|
||||
tempm1=tempm1->next;
|
||||
}
|
||||
*_itabbuf=tabbuf;
|
||||
*_itabbuf2=tabbuf2;
|
||||
}
|
||||
tempm1=tempm->sub;
|
||||
while (tempm1) {
|
||||
tempm2=tempm1->next;
|
||||
if (tempm1->attr & _ATTR_DIR) {
|
||||
tempc=tempm1->user_data;
|
||||
CDFillPathTable(tempm1,_itabbuf,_itabbuf2,tempc->path_entry_num,
|
||||
big_endian,first_free,cur_level+1,output_level);
|
||||
}
|
||||
tempm1=tempm2;
|
||||
}
|
||||
}
|
||||
|
||||
class CElTorito
|
||||
{
|
||||
U16 w[16];
|
||||
U8 bootable; //88=bootable 00=not bootable
|
||||
U8 media_type; //0=no emulation 4=hard disk
|
||||
U16 load_seg; //0000->07C0
|
||||
U8 sys_type;
|
||||
U8 zero;
|
||||
U16 sect_cnt;
|
||||
U32 load_rba; //start addr of virtual disk
|
||||
U8 zero2[20];
|
||||
};
|
||||
|
||||
/****
|
||||
#define PROD_CDROM_CFG "b10x20000\nt3 \n\n\n\n\n"
|
||||
U0 MakeMyISO()
|
||||
{
|
||||
Fmt('B',TRUE,FALSE);
|
||||
CopyTree("::/SparrowOS","B:/SparrowOS");
|
||||
//Del("B:/SparrowOS/Adam/WordStat/WSDefs.DAT");
|
||||
Auto(PROD_CDROM_CFG);
|
||||
InstallBoot('B','T');
|
||||
CDFileCreate(,"B:/*","",BOOTCD_BIN_Z);
|
||||
}
|
||||
****/
|
||||
|
||||
|
||||
|
||||
I have the following code in my start-up script.
|
||||
|
||||
'E' is my primary hard drive SparrowOS partition
|
||||
|
||||
'T' is my CD/DVD drive
|
||||
|
||||
'Z' is a RAM temporary drive from which I make an ISO image.
|
||||
You could use a hard drive directory instead of RAM.
|
||||
|
||||
#define PROD_CDROM_CFG "b10x20000\nt3 \n\n\n\n\n"
|
||||
|
||||
U0 BurnProductionCDImage()
|
||||
{
|
||||
Cd("E:/SparrowOS");
|
||||
|
||||
//This enters my cfg
|
||||
//for compiling OSMain.
|
||||
Auto(PROD_CDROM_CFG);
|
||||
|
||||
InstallBoot('E','T');
|
||||
Fmt('Z',TRUE,FALSE);
|
||||
Drv('Z');
|
||||
DelTree("/SparrowOS");
|
||||
CopyTree("E:/SparrowOS","/SparrowOS");
|
||||
DelTree("/Temp");
|
||||
MkDir("/Temp");
|
||||
DelTree("/0000Boot");
|
||||
CopyTree("E:/0000Boot","/0000Boot");
|
||||
CDFileCreate(,"Z:/*",NULL,BOOTCD_BIN_Z); //sys_dft_iso_name
|
||||
CDImageWrite('T');
|
||||
}
|
||||
*/
|
||||
|
||||
Study my account examples my technique $LK,"Cfg Strs","FL:::/SparrowOS/Demo/AcctExample/TSAdam.CPP.Z,1"$ $LK,"Update Funs","FL:::/SparrowOS/Demo/AcctExample/TSDistribute.CPP.Z,1"$.
|
||||
****/
|
||||
|
||||
public I64 CDFileCreate(U8 *filename=NULL,U8 *src_files_find_mask,U8 *fu_flags=NULL,
|
||||
U8 *bootfile=NULL,I64 emulation=0)
|
||||
//NULL filename uses sys_dft_iso_name.
|
||||
//See the above sample code
|
||||
//0=no emu 2=1.44meg 4=hard drive
|
||||
|
||||
//Use "C:/*" if you want all files on the C: drive.
|
||||
//Default flags are "+r" recurse.
|
||||
|
||||
{
|
||||
CISO1PriDesc *iso =CAlloc(CD_BLK_SIZE),
|
||||
*iso1=CAlloc(CD_BLK_SIZE),
|
||||
*iso2=CAlloc(CD_BLK_SIZE),
|
||||
*iso3=CAlloc(CD_BLK_SIZE);
|
||||
CDirEntry *rootdir=CAlloc(sizeof(CDirEntry));
|
||||
I64 i,j,
|
||||
cur_blk=0,bootfile_cd_blks=0,tabsize,tabsize2,first_free,max_depth,
|
||||
fuf_flags=0;
|
||||
U32 *d;
|
||||
CElTorito *et=CAlloc(CD_BLK_SIZE);
|
||||
U8 *filename2,
|
||||
*zero_buf=CAlloc(CD_BLK_SIZE),
|
||||
*bootfile_buf=NULL;
|
||||
CISO1PathEntry *tabbuf=NULL,*tabbuf2=NULL,*itabbuf,*itabbuf2;
|
||||
Bool okay=TRUE;
|
||||
CFile *out_file=NULL;
|
||||
CISO1DirEntry *tempi;
|
||||
CCCDUserData *tempc;
|
||||
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
|
||||
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
|
||||
if (!filename)
|
||||
filename=sys_dft_iso_name;
|
||||
filename2=DftExt(filename,"ISO");
|
||||
|
||||
if (bootfile) {
|
||||
bootfile_buf=FileRead(bootfile,&bootfile_cd_blks);
|
||||
if (bootfile_cd_blks>CD_BLK_SIZE*4) {
|
||||
ST_ERR_ST "Boot files limited to 0x2000 bytes\n";
|
||||
goto done1;
|
||||
}
|
||||
bootfile_cd_blks=(bootfile_cd_blks+CD_BLK_SIZE-1)/CD_BLK_SIZE;
|
||||
}
|
||||
rootdir->attr=_ATTR_DIR;
|
||||
rootdir->sub=FilesFind(src_files_find_mask,fuf_flags);
|
||||
rootdir->datetime=GetCurTimeCDate;
|
||||
rootdir->user_data=CAlloc(sizeof(CCCDUserData));
|
||||
tempc=rootdir->user_data;
|
||||
tempc->path_entry_num=1;
|
||||
|
||||
if (okay) {
|
||||
cur_blk=CD_FILE_OFFSET>>2;
|
||||
if (bootfile_buf)
|
||||
//preboot and bootloader
|
||||
cur_blk+=1+bootfile_cd_blks;
|
||||
CDFileCreate2(out_file,rootdir,
|
||||
&iso->root_dir_record,
|
||||
&iso2->root_dir_record,
|
||||
&cur_blk,rootdir,FALSE);
|
||||
tabsize=sizeof(CISO1PathEntry);
|
||||
tabsize2=sizeof(CISO1PathEntry);
|
||||
max_depth=CDTableLen(rootdir,&tabsize,&tabsize2,1);
|
||||
FillU32Palindrome(&iso->path_table_size,tabsize);
|
||||
FillU32Palindrome(&iso2->path_table_size,tabsize2);
|
||||
tabsize=(tabsize+CD_BLK_SIZE-1)/CD_BLK_SIZE;
|
||||
cur_blk+=tabsize<<1;
|
||||
tabsize2=(tabsize2+CD_BLK_SIZE-1)/CD_BLK_SIZE;
|
||||
cur_blk+=tabsize2<<1;
|
||||
}
|
||||
if (okay) {
|
||||
if (FileAttr(filename2) & _ATTR_CONTIGUOUS)
|
||||
out_file=FOpen(filename2,"wc",cur_blk<<2);
|
||||
else
|
||||
out_file=FOpen(filename2,"w",cur_blk<<2);
|
||||
if (!out_file)
|
||||
okay=FALSE;
|
||||
}
|
||||
if (okay) {
|
||||
cur_blk=0;
|
||||
while (cur_blk<CD_FILE_OFFSET>>2) {
|
||||
FWBlks(out_file,zero_buf,cur_blk<<2,4);
|
||||
cur_blk++;
|
||||
}
|
||||
iso->type=ISO1T_PRI_VOL_DESC;
|
||||
StrCpy(iso->id,"CD001");
|
||||
iso->version=1;
|
||||
FillU16Palindrome(&iso->vol_set_size,1);
|
||||
FillU16Palindrome(&iso->vol_seq_num,1);
|
||||
FillU16Palindrome(&iso->log_block_size,CD_BLK_SIZE);
|
||||
iso->file_structure_version=1;
|
||||
|
||||
iso2->type=ISO1T_SUPPLEMENTARY_DESC;
|
||||
StrCpy(iso2->id,"CD001");
|
||||
iso2->version=1;
|
||||
FillU16Palindrome(&iso2->vol_set_size,1);
|
||||
FillU16Palindrome(&iso2->vol_seq_num,1);
|
||||
FillU16Palindrome(&iso2->log_block_size,CD_BLK_SIZE);
|
||||
iso2->file_structure_version=1;
|
||||
|
||||
iso1->type=ISO1T_BOOT_RECORD;
|
||||
StrCpy(iso1->id,"CD001");
|
||||
iso1->version=1;
|
||||
StrCpy(iso1(U8 *)+7,"EL TORITO SPECIFICATION");
|
||||
|
||||
cur_blk=CD_FILE_OFFSET>>2;
|
||||
|
||||
if (bootfile_buf) {
|
||||
d=iso1(U8 *)+0x47;
|
||||
*d=cur_blk;
|
||||
et->w[0]=1;
|
||||
StrCpy(&et->w[2],"SparrowOS");
|
||||
et->w[15]=0xAA55;
|
||||
j=0;
|
||||
for (i=0;i<16;i++) //Checksum
|
||||
j+=et->w[i];
|
||||
et->w[14]=-j;
|
||||
if (bootfile_buf)
|
||||
et->bootable=0x88;
|
||||
//0=no emu 2=1.44meg 4=hard drive
|
||||
et->media_type=emulation;
|
||||
et->sect_cnt=4; //5 seems like the limit, 4 is safer
|
||||
et->load_rba=cur_blk+1;
|
||||
//$AN,"CDBOOT","CDBOOT"$ See $LK,"CDBootFileCreate","MN:CDBootFileCreate"$
|
||||
//See $LK,"BootCdProbe","MN:BootCdProbe"$().
|
||||
"%X: Pre Boot Blk\n",cur_blk;
|
||||
FWBlks(out_file,et,cur_blk<<2,4);
|
||||
cur_blk++;
|
||||
|
||||
"%X: Boot Loader Blks\n",cur_blk;
|
||||
FWBlks(out_file,bootfile_buf,cur_blk<<2,bootfile_cd_blks<<2);
|
||||
cur_blk+=bootfile_cd_blks;
|
||||
}
|
||||
|
||||
CDFileCreate2(out_file,rootdir,
|
||||
&iso->root_dir_record,
|
||||
&iso2->root_dir_record,
|
||||
&cur_blk,rootdir,TRUE);
|
||||
|
||||
tabbuf=CAlloc(tabsize*CD_BLK_SIZE);
|
||||
iso->type_l_path_table=cur_blk;
|
||||
tabbuf->name_len=2; //Fill-in adam entry
|
||||
tempi=&iso->root_dir_record;
|
||||
tabbuf->blk=tempi->loc.little;
|
||||
tabbuf->parent_entry_num=1;
|
||||
tabbuf2=CAlloc(tabsize2*CD_BLK_SIZE);
|
||||
iso2->type_l_path_table=cur_blk+tabsize;
|
||||
tabbuf2->name_len=2; //Fill-in adam entry
|
||||
tempi=&iso2->root_dir_record;
|
||||
tabbuf2->blk=tempi->loc.little;
|
||||
tabbuf2->parent_entry_num=1;
|
||||
itabbuf=tabbuf+1;
|
||||
itabbuf2=tabbuf2+1;
|
||||
first_free=2;
|
||||
for (i=1;i<=max_depth;i++)
|
||||
CDFillPathTable(rootdir,&itabbuf,&itabbuf2,
|
||||
1,FALSE,&first_free,1,i);
|
||||
"%X: Path Table 0\n",cur_blk;
|
||||
FWBlks(out_file,tabbuf,cur_blk<<2,tabsize<<2);
|
||||
cur_blk+=tabsize;
|
||||
"%X: Path Table 1\n",cur_blk;
|
||||
FWBlks(out_file,tabbuf2,cur_blk<<2,tabsize2<<2);
|
||||
cur_blk+=tabsize2;
|
||||
|
||||
|
||||
MemSet(tabbuf,0,tabsize*CD_BLK_SIZE);
|
||||
iso->type_m_path_table=EndianU32(cur_blk);
|
||||
tabbuf->name_len=2; //Fill-in adam entry
|
||||
tempi=&iso->root_dir_record;
|
||||
tabbuf->blk=tempi->loc.big;
|
||||
tabbuf->parent_entry_num=EndianU16(1);
|
||||
MemSet(tabbuf2,0,tabsize2*CD_BLK_SIZE);
|
||||
iso2->type_m_path_table=EndianU32(cur_blk+tabsize);
|
||||
tabbuf2->name_len=2; //Fill-in adam entry
|
||||
tempi=&iso2->root_dir_record;
|
||||
tabbuf2->blk=tempi->loc.big;
|
||||
tabbuf2->parent_entry_num=EndianU16(1);
|
||||
itabbuf=tabbuf+1;
|
||||
itabbuf2=tabbuf2+1;
|
||||
first_free=2;
|
||||
for (i=1;i<=max_depth;i++)
|
||||
CDFillPathTable(rootdir,&itabbuf,&itabbuf2,
|
||||
1,TRUE,&first_free,1,i);
|
||||
"%X: Path Table 2\n",cur_blk;
|
||||
FWBlks(out_file,tabbuf,cur_blk<<2,tabsize<<2);
|
||||
cur_blk+=tabsize;
|
||||
"%X: Path Table 3\n",cur_blk;
|
||||
FWBlks(out_file,tabbuf2,cur_blk<<2,tabsize2<<2);
|
||||
cur_blk+=tabsize2;
|
||||
|
||||
CDirListDel2(rootdir);
|
||||
FillU32Palindrome(&iso->vol_space_size,cur_blk);
|
||||
FillU32Palindrome(&iso2->vol_space_size,cur_blk);
|
||||
FWBlks(out_file,iso,16<<2,4);
|
||||
|
||||
iso3->type=ISO1T_TERMINATOR;
|
||||
StrCpy(iso3->id,"CD001");
|
||||
iso3->version=1;
|
||||
if (bootfile_buf) {
|
||||
FWBlks(out_file,iso1,17<<2,4);
|
||||
FWBlks(out_file,iso2,18<<2,4);
|
||||
FWBlks(out_file,iso3,19<<2,4);
|
||||
} else {
|
||||
FWBlks(out_file,iso2,17<<2,4);
|
||||
FWBlks(out_file,iso3,18<<2,4);
|
||||
}
|
||||
} else
|
||||
cur_blk=0;
|
||||
|
||||
FClose(out_file);
|
||||
Free(tabbuf);
|
||||
Free(tabbuf2);
|
||||
done1:
|
||||
Free(bootfile_buf);
|
||||
Free(filename2);
|
||||
Free(et);
|
||||
Free(zero_buf);
|
||||
Free(iso);
|
||||
Free(iso1);
|
||||
Free(iso2);
|
||||
Free(iso3);
|
||||
return cur_blk;
|
||||
}
|
||||
#help_index ""
|
||||
@@ -0,0 +1,765 @@
|
||||
#help_index "Doc/Output"
|
||||
U0 CDirFileDoc(CDoc *doc,CDirEntry *tempm)
|
||||
{
|
||||
CDocEntry *doc_e;
|
||||
while (tempm) {
|
||||
if (tempm->attr & _ATTR_DIR) {
|
||||
doc_e=DocPrintF(doc,"$$TR,\"%s\"$$",tempm->name);
|
||||
doc_e->user_data=tempm;
|
||||
tempm->user_data=doc_e;
|
||||
DocPutS(doc,"\n$$ID,+2$$");
|
||||
if (tempm->sub)
|
||||
CDirFileDoc(doc,tempm->sub);
|
||||
DocPutS(doc,"$$ID,-2$$");
|
||||
} else {
|
||||
doc_e=DocPrintF(doc,"$$MU-LE,\"%s\"$$",
|
||||
tempm->name);
|
||||
doc_e->user_data=tempm;
|
||||
tempm->user_data=doc_e;
|
||||
DocPutS(doc,"\n");
|
||||
}
|
||||
tempm=tempm->next;
|
||||
}
|
||||
}
|
||||
|
||||
#help_index "File/Cmd Line (Typically);Cmd Line (Typically)"
|
||||
|
||||
class CFMUncollapsedList
|
||||
{
|
||||
CFMUncollapsedList *next;
|
||||
U8 *name;
|
||||
};
|
||||
|
||||
CFMUncollapsedList *FMCollectUncollapsedList(CDoc *doc)
|
||||
{
|
||||
CDocEntry *doc_e=doc->root.next;
|
||||
CFMUncollapsedList *result=NULL,*tempc;
|
||||
CDirEntry *tempm;
|
||||
while (doc_e!=doc) {
|
||||
if (doc_e->type_u8==DOCT_TREE) {
|
||||
if (!(doc_e->flags1&DOCEF1_CHECKED_COLLAPSED)) {
|
||||
if (tempm=doc_e->user_data) {
|
||||
tempc=MAlloc(sizeof(CFMUncollapsedList));
|
||||
tempc->next=result;
|
||||
result=tempc;
|
||||
tempc->name=StrNew(tempm->full_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
doc_e=doc_e->next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 FMMarkUncollapsed(CDoc *doc,CFMUncollapsedList *tempc,U8 *cur_entry,U8 *next_entry)
|
||||
{
|
||||
CDocEntry *doc_e=doc->root.next;
|
||||
CFMUncollapsedList *tempc1;
|
||||
CDirEntry *tempm;
|
||||
while (doc_e!=doc) {
|
||||
if (doc_e->type_u8==DOCT_TREE) {
|
||||
tempm=doc_e->user_data;
|
||||
tempc1=tempc;
|
||||
while (tempc1) {
|
||||
if (!StrCmp(tempc1->name,tempm->full_name)) {
|
||||
doc_e->flags1&=~DOCEF1_CHECKED_COLLAPSED;
|
||||
break;
|
||||
}
|
||||
tempc1=tempc1->next;
|
||||
}
|
||||
if (cur_entry) {
|
||||
if (!StrNCmp(cur_entry,tempm->full_name,StrLen(tempm->full_name))) {
|
||||
doc->cur_entry=doc_e;
|
||||
if (StrLen(tempm->full_name)==StrLen(cur_entry))
|
||||
cur_entry=NULL;
|
||||
} else if (next_entry) {
|
||||
if (!StrNCmp(next_entry,tempm->full_name,StrLen(tempm->full_name))) {
|
||||
doc->cur_entry=doc_e;
|
||||
if (StrLen(tempm->full_name)==StrLen(next_entry))
|
||||
cur_entry=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (doc_e->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_e->user_data;
|
||||
if (cur_entry) {
|
||||
if (!StrNCmp(cur_entry,tempm->full_name,StrLen(tempm->full_name))) {
|
||||
doc->cur_entry=doc_e;
|
||||
if (StrLen(tempm->full_name)==StrLen(cur_entry))
|
||||
cur_entry=NULL;
|
||||
} else if (next_entry) {
|
||||
if (!StrNCmp(next_entry,tempm->full_name,StrLen(tempm->full_name))) {
|
||||
doc->cur_entry=doc_e;
|
||||
if (StrLen(tempm->full_name)==StrLen(next_entry))
|
||||
cur_entry=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
doc_e=doc_e->next;
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMDelUncollapsedList(CFMUncollapsedList *tempc)
|
||||
{
|
||||
CFMUncollapsedList *tempc1;
|
||||
while (tempc) {
|
||||
tempc1=tempc->next;
|
||||
Free(tempc->name);
|
||||
Free(tempc);
|
||||
tempc=tempc1;
|
||||
}
|
||||
}
|
||||
|
||||
CDirEntry *FMRebuildDocDrv(U8 drv_let,CDoc *doc,CDirEntry **_root,Bool init)
|
||||
{
|
||||
CDocEntry *doc_e;
|
||||
CDirEntry *tempm,*tempm1;
|
||||
U8 *st;
|
||||
tempm=CAlloc(sizeof(CDirEntry));
|
||||
tempm->full_name=MSPrintF("%C:/",drv_let);
|
||||
tempm->attr=_ATTR_DIR;
|
||||
st=MSPrintF("%c:/*",drv_let);
|
||||
if (init)
|
||||
tempm->sub=tempm1=FilesFind(st,1<<FUf_RECURSE);
|
||||
else
|
||||
tempm1=NULL;
|
||||
Free(st);
|
||||
doc_e=DocPrintF(doc,"$$TR,\"%s\"$$",tempm->full_name);
|
||||
doc_e->user_data=tempm;
|
||||
tempm->user_data=doc_e;
|
||||
tempm->next=*_root;
|
||||
*_root=tempm;
|
||||
DocPutS(doc,"\n$$ID,+2$$");
|
||||
DocBottom(doc);
|
||||
if (init) {
|
||||
CDirFileDoc(doc,tempm1);
|
||||
while (tempm1) {
|
||||
tempm1->parent=tempm;
|
||||
tempm1=tempm1->next;
|
||||
}
|
||||
}
|
||||
DocPutS(doc,"$$ID,-2$$");
|
||||
return tempm;
|
||||
}
|
||||
|
||||
U0 FMRebuildDoc(CDoc **_doc,CDirEntry **_root,I64 mode)
|
||||
{
|
||||
CPrt *p;
|
||||
I64 i;
|
||||
CDoc *doc=*_doc,*doc2=sys_clipboard_doc,*parent_doc;
|
||||
CFMUncollapsedList *tempc=NULL;
|
||||
U8 *cur_entry=NULL,*next_entry=NULL;
|
||||
CDocEntry *doc_ce;
|
||||
CDirEntry *tempm,*tempm1,*cur_tree_entry;
|
||||
if (!doc)
|
||||
parent_doc=DocCur;
|
||||
else {
|
||||
parent_doc=doc->parent_doc;
|
||||
DocQueRem(doc);
|
||||
DocUnlock(doc);
|
||||
WinMgrSync;
|
||||
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);
|
||||
tempm=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)
|
||||
tempm=doc_ce->user_data;
|
||||
else
|
||||
tempm=NULL;
|
||||
if (tempm) {
|
||||
tempm1=tempm->parent;
|
||||
while (tempm1) {
|
||||
if (tempm1==cur_tree_entry) {
|
||||
tempm=NULL;
|
||||
break;
|
||||
} else
|
||||
tempm1=tempm1->parent;
|
||||
}
|
||||
if (tempm)
|
||||
break;
|
||||
}
|
||||
doc_ce=doc_ce->next;
|
||||
}
|
||||
if (tempm)
|
||||
next_entry=StrNew(tempm->full_name);
|
||||
|
||||
tempc=FMCollectUncollapsedList(doc);
|
||||
DocDel(doc);
|
||||
}
|
||||
if (*_root) {
|
||||
CDirListDel(*_root);
|
||||
*_root=NULL;
|
||||
}
|
||||
doc=DocNew;
|
||||
StrCpy(doc->desc,"FileMan");
|
||||
doc->parent_doc=parent_doc;
|
||||
doc->flags|=DOCF_FORM;
|
||||
switch (mode) {
|
||||
case FM_NORMAL:
|
||||
DocPutS(doc,"$$FG,PURPLE$$File Manager$$FG$$\n\n$$LK,\"Click for Help\",\"FI:::/SparrowOS/Doc/FileMgr.TXT.Z\"$$\n\n");
|
||||
break;
|
||||
case FM_PICK_FILE:
|
||||
DocPutS(doc,"$$FG,PURPLE$$Pick file and press <ESC>$$FG$$\n\n");
|
||||
doc->flags|=DOCF_MIN_SIZE;
|
||||
break;
|
||||
case FM_PICK_DIR:
|
||||
DocPutS(doc,"$$FG,PURPLE$$Pick directory and press <ESC>$$FG$$\n\n");
|
||||
doc->flags|=DOCF_MIN_SIZE;
|
||||
break;
|
||||
}
|
||||
for (i=0;i<NUM_PRTS;i++) {
|
||||
p=&sys_prts[i];
|
||||
if (p->type==PT_NATIVE||p->type==PT_FAT32)
|
||||
FMRebuildDocDrv(Prt2Drv(p),doc,_root,TRUE);
|
||||
else if (p->type==PT_ISO9660) {
|
||||
if (p->bdev->flags&BDF_INITIALIZED)
|
||||
tempm=FMRebuildDocDrv(Prt2Drv(p),doc,_root,TRUE);
|
||||
else {
|
||||
tempm=FMRebuildDocDrv(Prt2Drv(p),doc,_root,FALSE);
|
||||
tempm->flags|=DEF_NOT_INITIALIZED;
|
||||
}
|
||||
tempm->flags|=DEF_REMOVABLE;
|
||||
}
|
||||
}
|
||||
DocHome(doc);
|
||||
FMMarkUncollapsed(doc,tempc,cur_entry,next_entry);
|
||||
DocCenter(doc);
|
||||
DocRst(doc2,TRUE);
|
||||
FMDelUncollapsedList(tempc);
|
||||
Free(cur_entry);
|
||||
Free(next_entry);
|
||||
*_doc=doc;
|
||||
DocLock(doc);
|
||||
DocQueRem(DocCur);
|
||||
DocQueIns(doc,Fs->last_doc);
|
||||
}
|
||||
|
||||
U0 FMRename(CDoc *doc)
|
||||
{
|
||||
CEdFileName fn;
|
||||
CDocEntry *doc_e=doc->cur_entry;
|
||||
CDirEntry *tempm=NULL,*parent;
|
||||
if (doc_e->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_e->user_data;
|
||||
if (parent=tempm->parent) {
|
||||
Cd(parent->full_name);
|
||||
StrCpy(fn.name,tempm->name);
|
||||
if (DocFormDo(fn.name,"CEdFileName")) {
|
||||
Silent(ON);
|
||||
Move(tempm->name,fn.name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
} else if (doc_e->type_u8==DOCT_TREE) {
|
||||
tempm=doc_e->user_data;
|
||||
if (parent=tempm->parent) {
|
||||
Cd(parent->full_name);
|
||||
StrCpy(fn.name,tempm->name);
|
||||
if (DocFormDo(fn.name,"CEdFileName")) {
|
||||
if (StrCmp(tempm->name,fn.name)) {
|
||||
Silent(ON);
|
||||
if (CopyTree(tempm->name,fn.name))
|
||||
DelTree(tempm->name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMMkDir(CDoc *doc)
|
||||
{
|
||||
CEdFileName fn;
|
||||
CDocEntry *doc_e=doc->cur_entry;
|
||||
CDirEntry *tempm=NULL,*parent;
|
||||
*fn.name=0;
|
||||
if (doc_e->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_e->user_data;
|
||||
if (parent=tempm->parent) {
|
||||
Cd(parent->full_name);
|
||||
if (DocFormDo(fn.name,"CEdFileName")) {
|
||||
Silent(ON);
|
||||
MkDir(fn.name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
} else if (doc_e->type_u8==DOCT_TREE) {
|
||||
tempm=doc_e->user_data;
|
||||
Cd(tempm->full_name);
|
||||
if (DocFormDo(fn.name,"CEdFileName")) {
|
||||
Silent(ON);
|
||||
MkDir(fn.name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMDelete(CDoc *doc)
|
||||
{
|
||||
U8 *st;
|
||||
CDocEntry *doc_ce=doc->cur_entry;
|
||||
CDirEntry *tempm;
|
||||
if (doc_ce->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_ce->user_data;
|
||||
Silent(ON);
|
||||
st=MSPrintF("Delete: %s",tempm->full_name);
|
||||
if (PopUpCancelOk(st))
|
||||
Del(tempm->full_name);
|
||||
Free(st);
|
||||
Silent(OFF);
|
||||
} else if (doc_ce->type_u8==DOCT_TREE) {
|
||||
tempm=doc_ce->user_data;
|
||||
Silent(ON);
|
||||
st=MSPrintF("Delete: %s",tempm->full_name);
|
||||
if (PopUpCancelOk(st))
|
||||
DelTree(tempm->full_name);
|
||||
Free(st);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMMount(CDoc *doc)
|
||||
{
|
||||
CDocEntry *doc_ce=doc->cur_entry;
|
||||
CDirEntry *tempm;
|
||||
if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm=doc_ce->user_data;
|
||||
else
|
||||
tempm=NULL;
|
||||
if (tempm) {
|
||||
while (tempm->parent)
|
||||
tempm=tempm->parent;
|
||||
Silent(ON);
|
||||
ChgDsk(*tempm->full_name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMFmtDrv(CDoc *doc)
|
||||
{
|
||||
CDocEntry *doc_ce=doc->cur_entry;
|
||||
CDirEntry *tempm;
|
||||
U8 *st=NULL;
|
||||
if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm=doc_ce->user_data;
|
||||
else
|
||||
tempm=NULL;
|
||||
if (tempm) {
|
||||
while (tempm->parent)
|
||||
tempm=tempm->parent;
|
||||
st=MSPrintF("Format Drive '%c'?\nAre You Sure?\n",*tempm->full_name);
|
||||
if (PopUpCancelOk(st)) {
|
||||
Silent(ON);
|
||||
Fmt(*tempm->full_name,TRUE,FALSE);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
Free(st);
|
||||
}
|
||||
|
||||
U0 FMMakeISO(CDoc *doc)
|
||||
{
|
||||
CDocEntry *doc_ce=doc->cur_entry;
|
||||
CDirEntry *tempm;
|
||||
U8 *st;
|
||||
if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm=doc_ce->user_data;
|
||||
else
|
||||
tempm=NULL;
|
||||
if (tempm) {
|
||||
if (doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm=tempm->parent;
|
||||
if (tempm && *tempm->full_name) {
|
||||
Silent(ON);
|
||||
if (tempm->full_name[StrLen(tempm->full_name)-1]=='/')
|
||||
st=MSPrintF("%s*",tempm->full_name);
|
||||
else
|
||||
st=MSPrintF("%s/*",tempm->full_name);
|
||||
CDFileCreate(,st);
|
||||
Free(st);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMBurnISO(CDoc *doc)
|
||||
{
|
||||
CDocEntry *doc_ce=doc->cur_entry;
|
||||
CDirEntry *tempm;
|
||||
if (doc_ce->type_u8==DOCT_TREE || doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm=doc_ce->user_data;
|
||||
else
|
||||
tempm=NULL;
|
||||
if (tempm) {
|
||||
while (tempm->parent)
|
||||
tempm=tempm->parent;
|
||||
Silent(ON);
|
||||
CDImageWrite(*tempm->full_name);
|
||||
Silent(OFF);
|
||||
}
|
||||
}
|
||||
|
||||
U0 FMCopy(CDoc *doc)
|
||||
{
|
||||
CDoc *doc2=sys_clipboard_doc;
|
||||
U8 *st;
|
||||
CDocEntry *doc_ce=doc->cur_entry,*doc_e;
|
||||
CDirEntry *tempm,*tempm1=NULL,*tempm2;
|
||||
Bool unlock_doc2=DocLock(doc2);
|
||||
doc_e=doc2->root.next;
|
||||
|
||||
tempm1=doc_ce->user_data;
|
||||
if (doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tempm1=tempm1->parent;
|
||||
else if (doc_ce->type_u8!=DOCT_TREE)
|
||||
tempm1=NULL;
|
||||
if (tempm1) {
|
||||
while (doc_e!=doc2) {
|
||||
if (doc_e->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_e->user_data;
|
||||
tempm->flags|=DEF_PROCESSED;
|
||||
tempm2=tempm->parent;
|
||||
if (!tempm2 || !(tempm2->flags&DEF_PROCESSED)) {
|
||||
Silent(ON);
|
||||
Copy(tempm->full_name,tempm1->full_name);
|
||||
Silent(OFF);
|
||||
}
|
||||
} else if (doc_e->type_u8==DOCT_TREE) {
|
||||
tempm=doc_e->user_data;
|
||||
tempm->flags|=DEF_PROCESSED;
|
||||
tempm2=tempm->parent;
|
||||
if (!tempm2 || !(tempm2->flags&DEF_PROCESSED)) {
|
||||
Silent(ON);
|
||||
if (*tempm1->name)
|
||||
st=MSPrintF("%s/%s",tempm1->full_name,tempm->name);
|
||||
else
|
||||
st=MSPrintF("%s%s",tempm1->full_name,tempm->name);
|
||||
CopyTree(tempm->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_MAKE_ISO 9
|
||||
#define FMR_BURN_ISO 10
|
||||
#define FMR_HELP 11
|
||||
|
||||
I64 PopUpCancelPasteDel(U8 *header=NULL,U8 *footer=NULL)
|
||||
{
|
||||
I64 i;
|
||||
CDoc *doc=DocNew;
|
||||
if (header) DocPutS(doc,header);
|
||||
DocPutS(doc,"$$CM+LX,1,1 $$$$BT,\"INCLUDE \",FMR_INCLUDE$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"ADAM INCLUDE \",FMR_ADAM_INCLUDE$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"DELETE \",FMR_DELETE$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"RENAME \",FMR_RENAME$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"MAKE DIRECTORY \",FMR_MKDIR$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"PLAIN-TEXT EDIT \",FMR_PLAIN$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"PASTE CLIPBOARD FILES \",FMR_PASTE$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"CHANGE DISK(MOUNT IT) \",FMR_CHG_DSK$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"FORMAT \",FMR_FORMAT$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"MAKE ISO (CD-ROM) FILE\",FMR_MAKE_ISO$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"BURN ISO (CD-ROM) FILE\",FMR_BURN_ISO$$"
|
||||
"$$CM+LX,1,3 $$$$BT,\"HELP \",FMR_HELP$$"
|
||||
"$$CM+LX,27,0$$$$BT,\"CANCEL \",DOCM_CANCEL$$\n");
|
||||
if (footer) DocPutS(doc,footer);
|
||||
i=PopUpMenu(doc);
|
||||
DocDel(doc);
|
||||
return i;
|
||||
}
|
||||
|
||||
U0 FMRightClick()
|
||||
{
|
||||
switch (PopUpCancelPasteDel) {
|
||||
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,'m',0);
|
||||
break;
|
||||
case FMR_FORMAT:
|
||||
Msg(MSG_KEY_DOWN,'f',0);
|
||||
break;
|
||||
case FMR_MAKE_ISO:
|
||||
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_ip_str=NULL;
|
||||
U0 (*fp_old_final_screen_update)(CDC *dc);
|
||||
|
||||
U0 FMFinalScreenUpdate(CDC *dc)
|
||||
{
|
||||
if (fm_ip_str) {
|
||||
dc->color=LTRED;
|
||||
GrPutS(dc,ipx,ipy,fm_ip_str);
|
||||
}
|
||||
(*fp_old_final_screen_update)(dc);
|
||||
}
|
||||
|
||||
public U8 *FileMgr(I64 mode=FM_NORMAL,CTask *mem_task=NULL)
|
||||
{
|
||||
CDirEntry *root=NULL,*tempm,*tempm1,*tempm2;
|
||||
I64 sc,ch,p1,p2,msg_code;
|
||||
CDoc *doc=NULL,*old_doc=DocCur;
|
||||
U8 *result=NULL,*st,*st2,*old_cur_dir=CurDir;
|
||||
CDocEntry *doc_ce=NULL,*doc_e;
|
||||
Bool okay;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
|
||||
fp_old_final_screen_update=fp_final_screen_update;
|
||||
MenuFilePush("::/SparrowOS/Doc/FileMgrPullDown.TXT.Z");
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
if (tempm1=CdDir(root,old_cur_dir))
|
||||
doc->cur_entry=tempm1->user_data;
|
||||
while (tempm1) {
|
||||
if (tempm1->attr&_ATTR_DIR)
|
||||
tempm1->user_data(CDocEntry *)->flags1&=~DOCEF1_CHECKED_COLLAPSED;
|
||||
tempm1=tempm1->parent;
|
||||
}
|
||||
do {
|
||||
DocUnlock(doc);
|
||||
do msg_code=GetMsg(&p1,&p2,
|
||||
1<<MSG_KEY_DOWN|1<<MSG_IP_L_DOWN|1<<MSG_IP_L_UP|
|
||||
1<<MSG_IP_R_UP);
|
||||
while (Fs!=sys_focus_task);
|
||||
DocLock(doc);
|
||||
switch (msg_code) {
|
||||
case MSG_IP_R_UP:
|
||||
DocUnlock(doc);
|
||||
FMRightClick;
|
||||
DocLock(doc);
|
||||
break;
|
||||
case MSG_IP_L_DOWN:
|
||||
doc_ce=doc->cur_entry;
|
||||
fm_ip_str=doc_ce->tag;
|
||||
fp_final_screen_update=&FMFinalScreenUpdate;
|
||||
break;
|
||||
case MSG_IP_L_UP:
|
||||
if (doc_ce) {
|
||||
fp_final_screen_update=fp_old_final_screen_update;
|
||||
if (SetCursorPos(Fs,p1/FONT_WIDTH+Fs->win_left+Fs->win_scroll_x/FONT_WIDTH,p2/FONT_HEIGHT+Fs->win_top+Fs->win_scroll_y/FONT_HEIGHT,TRUE)) {
|
||||
doc_e=doc->cur_entry;
|
||||
if (doc_e!=doc_ce) {
|
||||
st2=NULL;
|
||||
if (doc_e->type_u8==DOCT_MENU_VAL) {
|
||||
tempm1=doc_e->user_data;
|
||||
if (tempm1=tempm1->parent)
|
||||
st2=StrNew(tempm1->full_name);
|
||||
} else if (doc_e->type_u8==DOCT_TREE) {
|
||||
tempm1=doc_e->user_data;
|
||||
st2=StrNew(tempm1->full_name);
|
||||
}
|
||||
if (st2 && doc_ce->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc_ce->user_data;
|
||||
Silent(ON);
|
||||
Move(tempm->full_name,st2);
|
||||
Silent(OFF);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
} else if (st2 && doc_ce->type_u8==DOCT_TREE) {
|
||||
tempm=doc_ce->user_data;
|
||||
okay=TRUE;
|
||||
tempm2=tempm1;
|
||||
while (tempm2) {
|
||||
if (tempm2!=tempm)
|
||||
tempm2=tempm2->parent;
|
||||
else {
|
||||
okay=FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (okay) {
|
||||
if (*tempm1->name)
|
||||
st=MSPrintF("%s/%s",tempm1->full_name,tempm->name);
|
||||
else
|
||||
st=MSPrintF("%s%s",tempm1->full_name,tempm->name);
|
||||
if (StrCmp(tempm->full_name,st)) {
|
||||
Silent(ON);
|
||||
CopyTree(tempm->full_name,st);
|
||||
DelTree(tempm->full_name);
|
||||
Silent(OFF);
|
||||
FMRebuildDoc(&doc,&root,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=p1; sc=p2;
|
||||
if (sc.u8[0]==SC_DELETE && !(sc&(SCF_SHIFT|SCF_CTRL)))
|
||||
ch=CH_CTRLY;
|
||||
if (ch && sc&SCF_ALT) goto regular_key;
|
||||
switch (ch) {
|
||||
case CH_NEW_LINE:
|
||||
DocUnlock(doc);
|
||||
FMRightClick;
|
||||
DocLock(doc);
|
||||
break;
|
||||
case CH_CTRLV:
|
||||
FMCopy(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'r':
|
||||
DocUnlock(doc);
|
||||
FMRename(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'd':
|
||||
DocUnlock(doc);
|
||||
FMMkDir(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case CH_CTRLY:
|
||||
DocUnlock(doc);
|
||||
FMDelete(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'm':
|
||||
DocUnlock(doc);
|
||||
FMMount(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'M':
|
||||
DocUnlock(doc);
|
||||
FMMakeISO(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'B':
|
||||
DocUnlock(doc);
|
||||
FMBurnISO(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
break;
|
||||
case 'f':
|
||||
DocUnlock(doc);
|
||||
FMFmtDrv(doc);
|
||||
FMRebuildDoc(&doc,&root,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 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 regular_key;
|
||||
break;
|
||||
case CH_ESC:
|
||||
doc_ce=doc->cur_entry;
|
||||
tempm=doc_ce->user_data;
|
||||
if (mode==FM_PICK_FILE && doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
result=StrNew(tempm->full_name,mem_task);
|
||||
else if (mode==FM_PICK_DIR) {
|
||||
if (doc_ce->type_u8==DOCT_TREE)
|
||||
result=StrNew(tempm->full_name,mem_task);
|
||||
else if (doc_ce->type_u8==DOCT_MENU_VAL && (tempm=tempm->parent))
|
||||
result=StrNew(tempm->full_name,mem_task);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (sc.u8[0]==SC_INS && sc&SCF_SHIFT && !(sc&SCF_CTRL)) {
|
||||
FMCopy(doc);
|
||||
FMRebuildDoc(&doc,&root,mode);
|
||||
} else if (sc.u8[0]==SC_F5) {
|
||||
if (doc->cur_entry->type_u8==DOCT_MENU_VAL) {
|
||||
tempm=doc->cur_entry->user_data;
|
||||
DocUnlock(doc);
|
||||
if (sc&SCF_SHIFT)
|
||||
AdamFile(tempm->full_name);
|
||||
else
|
||||
PopUpFile(tempm->full_name);
|
||||
DocLock(doc);
|
||||
}
|
||||
} else {
|
||||
regular_key:
|
||||
DocUnlock(doc);
|
||||
PutKey(ch,sc);
|
||||
DocLock(doc);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
|
||||
fp_final_screen_update=fp_old_final_screen_update;
|
||||
DocQueRem(doc);
|
||||
DocQueIns(old_doc,Fs->last_doc);
|
||||
SettingsPop;
|
||||
DocDel(doc);
|
||||
CDirListDel(root);
|
||||
Cd(old_cur_dir);
|
||||
Free(old_cur_dir);
|
||||
if (mode!=FM_NORMAL && !result)
|
||||
result=StrNew("",mem_task);
|
||||
MenuPop;
|
||||
return result;
|
||||
}
|
||||
#help_index ""
|
||||
Reference in new issue
Block a user