Subversion Repositories Kolibri OS

Rev

Rev 5676 | Blame | Last modification | View Log | Download | RSS feed

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