Subversion Repositories Kolibri OS

Rev

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

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