Subversion Repositories Kolibri OS

Rev

Rev 5591 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_FILESYSTEM_H
  2. #define INCLUDE_FILESYSTEM_H
  3. #ifndef INCLUDE_KOLIBRI_H
  4. #include "../lib/kolibri.h"
  5. #endif
  6.  
  7. #ifndef INCLUDE_STRING_H
  8. #include "../lib/strings.h"
  9. #endif
  10.  
  11. :struct f70{
  12.         dword   func;
  13.         dword   param1;
  14.         dword   param2;
  15.         dword   param3;
  16.         dword   param4;
  17.         char    rezerv;
  18.         dword   name;
  19. };
  20.  
  21. :struct date
  22. {
  23.         byte day;
  24.         byte month;
  25.         word year;
  26. };
  27.  
  28. :struct BDVK {
  29.         dword   readonly:1, hidden:1, system:1, volume_label:1, isfolder:1, notarchived:1, :0;
  30.         byte    type_name;
  31.         byte    rez1, rez2, selected;
  32.         dword   timecreate;
  33.         date    datecreate;
  34.         dword   timelastaccess;
  35.         date    datelastaccess;
  36.         dword   timelastedit;
  37.         date    datelastedit;
  38.         dword   sizelo;
  39.         dword   sizehi;
  40.         char    name[518];
  41. };
  42.  
  43.  
  44. :void DrawDate(dword x, y, color, in_date)
  45. {
  46.         //char text[15];
  47.         EDI = in_date;
  48.         EAX = 47;
  49.         EBX = 2<<16;
  50.         EDX = x<<16+y;
  51.         ESI = 0x80<<24+color;
  52.         ECX = EDI.date.day;
  53.         $int 0x40;
  54.         EDX += 18<<16;
  55.         ECX = EDI.date.month;
  56.         $int 0x40;
  57.         EDX += 18<<16;
  58.         EBX = 4<<16;
  59.         ECX = EDI.date.year;
  60.         $int 0x40;
  61.         PutPixel(x+14,y+6,color);
  62.         PutPixel(x+32,y+6,color);
  63.         //sprintf(#text,"%d",EDI.date.year);
  64.         //WriteText(x, y, 0x80, 0x000000, #text);
  65. }
  66.  
  67.  
  68. ///////////////////////////
  69. //   Ïàðàìåòðû ôàéëà    //
  70. ///////////////////////////
  71. :f70 getinfo_file_70;
  72. :dword GetFileInfo(dword file_path, bdvk_struct)
  73. {    
  74.     getinfo_file_70.func = 5;
  75.     getinfo_file_70.param1 =
  76.     getinfo_file_70.param2 =
  77.     getinfo_file_70.param3 = 0;
  78.     getinfo_file_70.param4 = bdvk_struct;
  79.     getinfo_file_70.rezerv = 0;
  80.     getinfo_file_70.name = file_path;
  81.     $mov eax,70
  82.     $mov ebx,#getinfo_file_70.func
  83.     $int 0x40
  84. }
  85.  
  86. ///////////////////////////
  87. //   Èçìåíåíèå ïàðàìåòðîâ ôàéëà    //
  88. ///////////////////////////
  89. :f70 setinfo_file_70;
  90. :dword SetFileInfo(dword file_path, bdvk_struct)
  91. {    
  92.     setinfo_file_70.func = 6;
  93.     setinfo_file_70.param1 =
  94.     setinfo_file_70.param2 =
  95.     setinfo_file_70.param3 = 0;
  96.     setinfo_file_70.param4 = bdvk_struct;
  97.     setinfo_file_70.rezerv = 0;
  98.     setinfo_file_70.name = file_path;
  99.     $mov eax,70
  100.     $mov ebx,#setinfo_file_70.func
  101.     $int 0x40
  102. }
  103.  
  104. ///////////////////////////
  105. //   Çàïóñê ïðîãðàììû    //
  106. ///////////////////////////
  107. :f70 run_file_70;
  108. :signed int RunProgram(dword run_path, run_param)
  109. {      
  110.     run_file_70.func = 7;
  111.     run_file_70.param1 =
  112.     run_file_70.param3 =
  113.     run_file_70.param4 =
  114.     run_file_70.rezerv = 0;
  115.     run_file_70.param2 = run_param;
  116.     run_file_70.name = run_path;
  117.     $mov eax,70
  118.     $mov ebx,#run_file_70.func
  119.     $int 0x40
  120. }
  121.  
  122. ///////////////////////////
  123. //    Ñîçäàíèå ïàïêè     //
  124. ///////////////////////////
  125. :f70 create_dir_70;
  126. :int CreateDir(dword new_folder_path)
  127. {
  128.         create_dir_70.func = 9;
  129.         create_dir_70.param1 =
  130.         create_dir_70.param2 =
  131.         create_dir_70.param3 =
  132.         create_dir_70.param4 =
  133.         create_dir_70.rezerv = 0;
  134.         create_dir_70.name = new_folder_path;
  135.         $mov eax,70
  136.         $mov ebx,#create_dir_70.func
  137.         $int 0x40
  138. }
  139.  
  140. ////////////////////////////
  141. //  Óäàëåíèå ôàéëà/ïàïêè  //
  142. ////////////////////////////
  143. :f70 del_file_70;      
  144. :int DeleteFile(dword del_file_path)
  145. {    
  146.         del_file_70.func = 8;
  147.         del_file_70.param1 =
  148.         del_file_70.param2 =
  149.         del_file_70.param3 =
  150.         del_file_70.param4 =
  151.         del_file_70.rezerv = 0;
  152.         del_file_70.name = del_file_path;
  153.         $mov eax,70
  154.         $mov ebx,#del_file_70.func
  155.         $int 0x40
  156. }
  157.  
  158. ////////////////////////////
  159. //     Ïðî÷èòàòü ôàéë     //
  160. ////////////////////////////
  161. :f70 read_file_70;
  162. :int ReadFile(dword read_pos, read_file_size, read_buffer, read_file_path)
  163. {
  164.         read_file_70.func = 0;
  165.         read_file_70.param1 = read_pos;
  166.         read_file_70.param2 = 0;
  167.         read_file_70.param3 = read_file_size;
  168.         read_file_70.param4 = read_buffer;
  169.         read_file_70.rezerv = 0;
  170.         read_file_70.name = read_file_path;
  171.         $mov eax,70
  172.         $mov ebx,#read_file_70.func
  173.         $int 0x40
  174. }
  175.  
  176. ////////////////////////////
  177. //     Çàïèñàòü ôàéë      //
  178. ////////////////////////////
  179. :f70 write_file_70;
  180. :int WriteFile(dword write_file_size, write_buffer, write_file_path)
  181. {
  182.         write_file_70.func = 2;
  183.         write_file_70.param1 = 0;
  184.         write_file_70.param2 = 0;
  185.         write_file_70.param3 = write_file_size;
  186.         write_file_70.param4 = write_buffer;
  187.         write_file_70.rezerv = 0;
  188.         write_file_70.name = write_file_path;
  189.         $mov eax,70
  190.         $mov ebx,#write_file_70.func
  191.         $int 0x40
  192. }
  193.  
  194. //////////////////////////////////////////
  195. //     WriteInFileThatAlredyExists      //
  196. //////////////////////////////////////////
  197. :f70 write_file_offset_70;
  198. :int WriteFileWithOffset(dword write_data_size, write_buffer, write_file_path, offset)
  199. {
  200.         write_file_offset_70.func = 3;
  201.         write_file_offset_70.param1 = offset;
  202.         write_file_offset_70.param2 = 0;
  203.         write_file_offset_70.param3 = write_data_size;
  204.         write_file_offset_70.param4 = write_buffer;
  205.         write_file_offset_70.rezerv = 0;
  206.         write_file_offset_70.name = write_file_path;
  207.         $mov eax,70
  208.         $mov ebx,#write_file_offset_70.func
  209.         $int 0x40
  210. }  
  211.  
  212. ///////////////////////////
  213. //    Ïðî÷èòàòü ïàïêó    //
  214. ///////////////////////////
  215. :f70 read_dir_70;
  216. :int ReadDir(dword file_count, read_buffer, dir_path)
  217. {
  218.         read_dir_70.func = 1;
  219.         read_dir_70.param1 =
  220.         read_dir_70.param2 =
  221.         read_dir_70.rezerv = 0;
  222.         read_dir_70.param3 = file_count;
  223.         read_dir_70.param4 = read_buffer;
  224.         read_dir_70.name = dir_path;
  225.         $mov eax,70
  226.         $mov ebx,#read_dir_70.func
  227.         $int 0x40
  228. }
  229.  
  230. :char isdir(dword fpath)
  231. {
  232.         BDVK fpath_atr;
  233.         GetFileInfo(fpath, #fpath_atr);
  234.         return fpath_atr.isfolder;
  235. }
  236.  
  237. :int GetFile(dword buf, filesize, read_path)
  238. {
  239.         BDVK ReadFile_atr;
  240.         dword rBuf;
  241.         if (! GetFileInfo(read_path, #ReadFile_atr))
  242.         {
  243.                 rBuf = malloc(ReadFile_atr.sizelo);    
  244.                 if (! ReadFile(0, ReadFile_atr.sizelo, rBuf, read_path))
  245.                 {
  246.                         ESDWORD[buf] = rBuf;
  247.                         ESDWORD[filesize] = ReadFile_atr.sizelo;
  248.                         return 1;
  249.                 }
  250.         }
  251.         free(rBuf);
  252.         return 0;
  253. }
  254.  
  255. enum
  256. {
  257.         DIRS_ALL,
  258.         DIRS_NOROOT,
  259.         DIRS_ONLYREAL
  260. };
  261. :int GetDir(dword dir_buf, file_count, path, doptions)
  262. {
  263.         dword buf, fcount, error;
  264.         buf = malloc(32);
  265.         error = ReadDir(0, buf, path);
  266.         if (!error)
  267.         {
  268.                 fcount = ESDWORD[buf+8];
  269.                 buf = realloc(buf, fcount+1*304+32);
  270.                 ReadDir(fcount, buf, path);
  271.                 //fcount=EBX;
  272.  
  273.                 if (doptions == DIRS_ONLYREAL)
  274.                 {
  275.                         if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
  276.                         if (!strcmp("..",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
  277.                 }
  278.                 if (doptions == DIRS_NOROOT)
  279.                 {
  280.                         if (!strcmp(".",buf+72)) {fcount--; memmov(buf,buf+304,fcount*304);}
  281.                 }
  282.  
  283.                 ESDWORD[dir_buf] = buf;
  284.                 ESDWORD[file_count] = fcount;
  285.         }
  286.         else
  287.         {
  288.                 ESDWORD[file_count] = 0;
  289.                 ESDWORD[dir_buf] = free(buf);
  290.         }
  291.         return error;
  292. }
  293.  
  294. :dword notify(dword notify_param)
  295. {
  296.         return RunProgram("@notify", notify_param);
  297. }
  298.  
  299. :dword abspath(dword relative_path) //GetAbsolutePathFromRelative()
  300. {
  301.         char absolute_path[4096];
  302.         if (ESBYTE[relative_path]=='/')
  303.         {
  304.                 strcpy(#absolute_path, relative_path);
  305.         }
  306.         else
  307.         {
  308.                 strcpy(#absolute_path, #program_path);
  309.                 absolute_path[strrchr(#absolute_path, '/')] = '\0';
  310.                 strcat(#absolute_path, relative_path);
  311.         }
  312.         return #absolute_path;
  313. }
  314.  
  315. :byte ConvertSize_size_prefix[8];
  316. :dword ConvertSize(dword bytes)
  317. {
  318.   byte size_nm[4];
  319.   if (bytes>=1073741824) strncpy(#size_nm, "Gb",2);
  320.   else if (bytes>=1048576) strncpy(#size_nm, "Mb",2);
  321.   else if (bytes>=1024) strncpy(#size_nm, "Kb",2);
  322.   else strncpy(#size_nm, "b ",2);
  323.   while (bytes>1023) bytes/=1024;
  324.   sprintf(#ConvertSize_size_prefix,"%d %s",bytes,#size_nm);
  325.   return #ConvertSize_size_prefix;
  326. }
  327.  
  328. :dword ConvertSizeToKb(unsigned int bytes)
  329. {
  330.         unsigned char size[25]=0;
  331.         unsigned int kb;
  332.         dword kb_line;
  333.  
  334.         kb_line = itoa(bytes / 1024);
  335.         strcpy(#size, kb_line);
  336.         strcat(#size, " Kb");
  337.  
  338.         return #size;
  339. }
  340. #endif