Tmpdisk v0.6: show disks sizes, use much less memory

git-svn-id: svn://kolibrios.org@5482 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-02-27 01:44:22 +00:00
parent 14c0ef2d17
commit 324f214b01
4 changed files with 136 additions and 92 deletions

Binary file not shown.

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// êîíñîëü //////////////////// ///////////////////////// Console ////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
#ifdef LANG_RUS #ifdef LANG_RUS
@ -38,7 +38,6 @@ char Console_Work()
char size_t[256]; char size_t[256];
strlwr(#param); strlwr(#param);
// debug(#param);
switch (param[0]) switch (param[0])
{ {
@ -58,6 +57,7 @@ char Console_Work()
ioctl.inp_size = sizeof(del_disk); ioctl.inp_size = sizeof(del_disk);
ioctl.output = 0; ioctl.output = 0;
ioctl.out_size = 0; ioctl.out_size = 0;
disk_sizes[del_disk.DiskId] = 0;
break; break;
case 'a': //äîáàâèòü äèñê case 'a': //äîáàâèòü äèñê
debugln(ADD_DISK_TEXT); debugln(ADD_DISK_TEXT);
@ -80,6 +80,7 @@ char Console_Work()
ioctl.inp_size = sizeof(add_disk); ioctl.inp_size = sizeof(add_disk);
ioctl.output = 0; ioctl.output = 0;
ioctl.out_size = 0; ioctl.out_size = 0;
disk_sizes[add_disk.DiskId] = add_disk.DiskSize * 512;
break; break;
default: default:
debugln("unknown command line parameters"); debugln("unknown command line parameters");

View File

@ -1,6 +1,8 @@
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// GUI ////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
#include "..\lib\figures.h" #include "..\lib\figures.h"
#include "..\lib\mem.h"
#include "..\lib\dll.h"
#include "..\lib\lib.obj\box_lib.h" #include "..\lib\lib.obj\box_lib.h"
#ifdef LANG_RUS #ifdef LANG_RUS
@ -15,8 +17,8 @@
?define INTRO_TEXT_3 "<EFBFBD>®¯à®¡ã©â¥ ¤®¡ ¢¨âì ®¤¨­..." ?define INTRO_TEXT_3 "<EFBFBD>®¯à®¡ã©â¥ ¤®¡ ¢¨âì ®¤¨­..."
?define INTRO_TEXT_4 "<EFBFBD> §¬¥à:" ?define INTRO_TEXT_4 "<EFBFBD> §¬¥à:"
?define NOTIFY_TEXT_NO_DISK "„«ï ­ ç «  ¤®¡ ¢ì⥠å®âï ¡ë ®¤¨­ ¤¨áª" ?define NOTIFY_TEXT_NO_DISK "'„«ï ­ ç «  ¤®¡ ¢ì⥠å®âï ¡ë ®¤¨­ ¤¨áª' -W"
?define NOTIFY_TEXT_DISK_LIMIT "„®á⨣­ã⠯।¥« ª®«¨ç¥á⢠ ¢¨àâã «ì­ëå ¤¨áª®¢" ?define NOTIFY_TEXT_DISK_LIMIT "'„®á⨣­ã⠯।¥« ª®«¨ç¥á⢠ ¢¨àâã «ì­ëå ¤¨áª®¢' -W"
?define FREE_RAM_TEXT "<EFBFBD> §¬¥à ᢮¡®¤­®© ®¯¥à â¨¢­®© ¯ ¬ïâ¨: " ?define FREE_RAM_TEXT "<EFBFBD> §¬¥à ᢮¡®¤­®© ®¯¥à â¨¢­®© ¯ ¬ïâ¨: "
#else #else
@ -31,38 +33,36 @@
?define INTRO_TEXT_3 " Try to add one..." ?define INTRO_TEXT_3 " Try to add one..."
?define INTRO_TEXT_4 "Size:" ?define INTRO_TEXT_4 "Size:"
?define NOTIFY_TEXT_NO_DISK "You need to have at least one disk" ?define NOTIFY_TEXT_NO_DISK "'You need to have at least one disk' -W"
?define NOTIFY_TEXT_DISK_LIMIT "Reached the limit of the number of virtual disks" ?define NOTIFY_TEXT_DISK_LIMIT "'Reached the limit of the number of virtual disks' -W"
?define FREE_RAM_TEXT "Free RAM size: " ?define FREE_RAM_TEXT "Free RAM size: "
#endif #endif
struct path_string { unsigned char Item[256]; }; struct path_string { unsigned char Item[10]; };
path_string disk_list[40]; path_string disk_list[10];
dword devbuf; dword devbuf;
int disk_num; char disk_num;
int selected; char selected;
system_colors sc; system_colors sc;
proc_info Form; proc_info Form;
unsigned char dsize[30]; unsigned char icons[] = FROM "icons.raw";
unsigned char icons[14*56] = FROM "icons.raw";
#define TOPPANELH 50 #define TOPPANELH 50
#define BOTPANELH 20 #define BOTPANELH 20
int mouse_dd; int mouse_dd;
char disk_size[30]; char new_disk_size[5];
edit_box edit_disk_size= {50,0,5,0xffffff,0x94AECE,0x000000,0xffffff,0,4,#disk_size,#mouse_dd, 1000000000000010b}; edit_box edit_disk_size= {50,0,5,0xffffff,0x94AECE,0x000000,0xffffff,0,4,#new_disk_size,#mouse_dd, 1000000000000010b};
void Main_Window() void Main_Window()
{ {
unsigned int id, key, err; word id, key, err;
int i, x; int i, x;
mem_Init(); mem_Init();
if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Error while loading GUI library /sys/lib/boxlib.obj"); if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("Eror: library doesn't exists - boxlib");
GetSizeDisk(); GetSizeDisk();
edit_disk_size.left = strlen(INTRO_TEXT_4)*6 + 10; edit_disk_size.left = strlen(INTRO_TEXT_4)*6 + 10;
SetEventMask(0x27); SetEventMask(0x27);
@ -77,24 +77,9 @@ void Main_Window()
case evButton: case evButton:
id=GetButtonID(); id=GetButtonID();
if (id==1) ExitProcess(); if (id==1) return;
if (id==10) AddDisk(); if (id==10) AddDisk();
if (id==11) //del if (id==11) DelDisk();
{
_DEL_DISK:
if (disk_num==0)
{
notify(NOTIFY_TEXT_NO_DISK);
break;
}
param[0]='d';
param[1]=disk_list[selected].Item[3];
err = Console_Work();
if ((err!=0) && (err<7)) notify(rezult_text[err]);
pause(15);
GetDisks();
DrawTmpDisks();
}
if (id>=20) if (id>=20)
{ {
if (selected==id-20) OpenTmpDisk(); if (selected==id-20) OpenTmpDisk();
@ -104,14 +89,9 @@ void Main_Window()
break; break;
case evKey: case evKey:
key = GetKey(); key = GetKey();
if (key==9) if (TestBit(edit_disk_size.flags,2))
{
if ( !asm test edit_disk_size.flags, 2) edit_disk_size.flags=1000000000000010b;
else edit_disk_size.flags=1000000000000000b;
edit_box_draw stdcall (#edit_disk_size);
}
if ( asm test edit_disk_size.flags, 2)
{ {
if (key==185) AddDisk();
if (key==13) if (key==13)
{ {
edit_disk_size.flags=1000000000000000b; edit_disk_size.flags=1000000000000000b;
@ -121,39 +101,47 @@ void Main_Window()
edit_box_key stdcall(#edit_disk_size); edit_box_key stdcall(#edit_disk_size);
break; break;
} }
if (key==182) if (disk_num<>0) goto _DEL_DISK; switch(key)
if (key==185) AddDisk();
if (key==13) OpenTmpDisk();
if (key==178)
{ {
case 9:
if ( !asm test edit_disk_size.flags, 2) edit_disk_size.flags=1000000000000010b;
else edit_disk_size.flags=1000000000000000b;
edit_box_draw stdcall (#edit_disk_size);
break;
case 185:
AddDisk();
break;
case 182:
if (disk_num<>0) DelDisk();
break;
case 13:
OpenTmpDisk();
break;
case 178:
if (selected==0) break; if (selected==0) break;
selected--; selected--;
DrawTmpDisks(); DrawTmpDisks();
} break;
if (key==177) case 177:
{
if (selected+2>disk_num) break; if (selected+2>disk_num) break;
selected++; selected++;
DrawTmpDisks(); DrawTmpDisks();
} break;
if (key==176) case 176:
{
if (selected<3) break; if (selected<3) break;
selected-=3; selected-=3;
DrawTmpDisks(); DrawTmpDisks();
} break;
if (key==179) case 179:
{
if (selected+4>disk_num) break; if (selected+4>disk_num) break;
selected+=3; selected+=3;
DrawTmpDisks(); DrawTmpDisks();
break;
} }
//EAX=key<<8;
//edit_box_key stdcall(#edit_disk_size);
break; break;
case evReDraw: case evReDraw:
sc.get(); sc.get();
DefineAndDrawWindow(170,150,314,270,0x74,sc.work,"Virtual Disk Manager 0.5",0); DefineAndDrawWindow(170,150,314,270,0x74,sc.work,"Virtual Disk Manager 0.6",0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
if (Form.status_window>2) break; if (Form.status_window>2) break;
@ -174,19 +162,21 @@ void Main_Window()
} }
} }
void GetSizeDisk() void GetSizeDisk()
{ {
int fr; int fr;
fr = GetFreeRAM() / 5; fr = GetFreeRAM() / 5;
fr = itoa(fr / 2048); fr = itoa(fr / 2048);
strcpy(#disk_size, fr); strcpy(#new_disk_size, fr);
edit_disk_size.size = edit_disk_size.pos = strlen(#disk_size); edit_disk_size.size = edit_disk_size.pos = strlen(#new_disk_size);
edit_box_draw stdcall (#edit_disk_size); edit_box_draw stdcall (#edit_disk_size);
} }
void OpenTmpDisk() void OpenTmpDisk()
{ {
unsigned char eol_param[256]; unsigned char eol_param[10];
if (!disk_num) return; if (!disk_num) return;
strcpy(#eol_param, "/tmp#/1/"); strcpy(#eol_param, "/tmp#/1/");
eol_param[4] = disk_list[selected].Item[3]; eol_param[4] = disk_list[selected].Item[3];
@ -197,7 +187,7 @@ void OpenTmpDisk()
void GetDisks() void GetDisks()
{ {
unsigned int j, fcount=30; unsigned int j, fcount=30;
unsigned char disk_name[256]; unsigned char disk_name[10];
mem_Free(devbuf); mem_Free(devbuf);
devbuf= mem_Alloc(32); devbuf= mem_Alloc(32);
@ -219,13 +209,15 @@ void GetDisks()
} }
unsigned int disk_pos_x[]={13,13,13,83,83,83,153,153,153,223,223,223}; unsigned int disk_pos_x[]={13,13,13,85,85,85,157,157,157,229,229,229};
unsigned int disk_pos_y[]={60,85,110,60,85,110,60,85,110,60,85,110}; unsigned int disk_pos_y[]={60,95,130, 60, 95, 130, 60, 95,130, 60, 85,130};
void DrawTmpDisks() void DrawTmpDisks()
{ {
char free_ram_text[60]; char free_ram_text[60];
int i,FreeRAM=GetFreeRAM()/1024; int i;
int FreeRAM=GetFreeRAM()/1024;
DrawBar(0,51, Form.cwidth,Form.cheight-TOPPANELH-BOTPANELH-2, 0xFFFFFF); DrawBar(0,51, Form.cwidth,Form.cheight-TOPPANELH-BOTPANELH-2, 0xFFFFFF);
DrawBar(0,Form.cheight-BOTPANELH-1, Form.cwidth,1, sc.work_graph); DrawBar(0,Form.cheight-BOTPANELH-1, Form.cwidth,1, sc.work_graph);
DrawBar(0,Form.cheight-BOTPANELH, Form.cwidth,BOTPANELH, sc.work); DrawBar(0,Form.cheight-BOTPANELH, Form.cwidth,BOTPANELH, sc.work);
@ -244,16 +236,18 @@ void DrawTmpDisks()
for (i=0; i<10; i++) DeleteButton(20+i); for (i=0; i<10; i++) DeleteButton(20+i);
for (i=0; i<disk_num; i++) for (i=0; i<disk_num; i++)
{ {
DefineButton(disk_pos_x[i], disk_pos_y[i], 60, 20, 20+i, 0xFFFfff); DefineButton(disk_pos_x[i], disk_pos_y[i], 65, 30, 20+i, 0xFFFfff);
WriteText(disk_pos_x[i]+25,disk_pos_y[i]+6, 0x90, 0, #disk_list[i].Item); WriteText(disk_pos_x[i]+25,disk_pos_y[i]+6, 0x90, 0, #disk_list[i].Item);
_PutImage(disk_pos_x[i]+5,disk_pos_y[i]+4, 14,14, 3*14*14*3+#icons); WriteText(disk_pos_x[i]+25,disk_pos_y[i]+19, 0x80, 0x888888, ConvertSize(disk_sizes[i]));
if (selected==i) DrawRectangle(disk_pos_x[i], disk_pos_y[i], 60-1, 20-1, 0x00459A); _PutImage(disk_pos_x[i]+5,disk_pos_y[i]+4, 14,14, 2*14*14*3+#icons);
if (selected==i) DrawRectangle(disk_pos_x[i], disk_pos_y[i], 65-1, 30-1, 0x00459A);
} }
} }
void AddDisk() void AddDisk()
{ {
unsigned int i, j, err; byte i, j, err;
if (disk_num>=10) if (disk_num>=10)
{ {
notify(NOTIFY_TEXT_DISK_LIMIT); notify(NOTIFY_TEXT_DISK_LIMIT);
@ -273,7 +267,7 @@ void AddDisk()
param[1]=i+48; param[1]=i+48;
param[2]='s'; param[2]='s';
param[3]='\0'; param[3]='\0';
strcat(#param, #disk_size); strcat(#param, #new_disk_size);
err = Console_Work(); err = Console_Work();
if ((err!=0) && (err<7)) notify(rezult_text[err]); if ((err!=0) && (err<7)) notify(rezult_text[err]);
pause(5); pause(5);
@ -283,6 +277,24 @@ void AddDisk()
} }
void DelDisk()
{
byte err;
if (disk_num==0)
{
notify(NOTIFY_TEXT_NO_DISK);
return;
}
param[0]='d';
param[1]=disk_list[selected].Item[3];
err = byte Console_Work();
if ((err!=0) && (err<7)) notify(rezult_text[err]);
pause(15);
GetDisks();
DrawTmpDisks();
}

View File

@ -1,8 +1,13 @@
#define MEMSIZE 0xA0000 #define MEMSIZE 0xA0000
#include "..\lib\kolibri.h" #include "..\lib\kolibri.h"
#include "..\lib\mem.h"
#include "..\lib\strings.h" #include "..\lib\strings.h"
#include "..\lib\file_system.h" #include "..\lib\file_system.h"
#include "..\lib\dll.h"
#include "..\lib\lib.obj\libio_lib.h"
#include "..\lib\lib.obj\libini.h"
#ifndef AUTOBUILD #ifndef AUTOBUILD
#include "lang.h--" #include "lang.h--"
#endif #endif
@ -42,11 +47,13 @@ del_disk_struc del_disk;
int driver_handle; int driver_handle;
dword disk_sizes[10];
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// Code //////////////////// ///////////////////////// Code ////////////////////
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
#include "t_console.c" #include "t_console.c"
#include "t_window.c" #include "t_gui.c"
void main() void main()
@ -54,19 +61,43 @@ void main()
driver_handle = LoadDriver("tmpdisk"); driver_handle = LoadDriver("tmpdisk");
if (driver_handle==0) if (driver_handle==0)
{ {
notify("error: /rd1/1/drivers/tmpdisk.obj driver loading failed"); notify("'TmpDisk\nError: /rd1/1/drivers/tmpdisk.obj driver loading failed\nvirtual disk wouldn't be added' -tE");
notify("virtual disk wouldn't be added");
ExitProcess(); ExitProcess();
} }
GetDiskSizesFromIni();
if (param) if (param)
Console_Work(); Console_Work();
else else
Main_Window(); Main_Window();
SaveDiskSizesToIni();
ExitProcess(); ExitProcess();
} }
void GetDiskSizesFromIni()
{
char i, key[2];
if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini");
for (i=0; i<=9; i++)
{
key[0]=i+'0';
ini_get_int stdcall ("/sys/settings/tmpdisk.ini", "DiskSizes", #key, 0);
disk_sizes[i] = EAX;
}
}
void SaveDiskSizesToIni()
{
char i, key[2];
for (i=0; i<=9; i++)
{
key[0]=i+'0';
ini_set_int stdcall ("/sys/settings/tmpdisk.ini", "DiskSizes", #key, disk_sizes[i]);
}
}
stop: stop: