Subversion Repositories Kolibri OS

Rev

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

  1. // универсальность добавления /
  2. // относительный путь относительно программы
  3.  
  4. void copyf(dword params)
  5. {  
  6.         //copyf /sys/lib|/sys/lib2
  7.         char from[4096], to[4096];
  8.         BDVK from_atr;
  9.         int border;
  10.         mem_Init();
  11.         if (!params) { notify("Error: no copyf params!"); return; }
  12.         program_path[strrchr(#program_path, '/')] = 0x0;
  13.         border = strchr(params, '|');
  14.         if (!border) border = strchr(params, ' ');
  15.  
  16.         if (ESBYTE[params]<>'/')
  17.         {
  18.                 strcpy(#from, #program_path);
  19.                 strcat(#from, params);
  20.                 from[border+strlen(#program_path)-1]=NULL;
  21.         }
  22.         else
  23.         {
  24.                 strcat(#from, params);
  25.                 from[border-1]=NULL;           
  26.         }
  27.         strcpy(#to, params+border);
  28.  
  29.         GetFileInfo(#from, #from_atr);
  30.         if (TestBit(from_atr.attr, 4)==1)
  31.         {
  32.                 CopyFolder(#from, #to);
  33.         }
  34.         else
  35.         {
  36.                 CopyFile(#from, #to);
  37.         }
  38. }
  39.  
  40.  
  41. void CopyFolder(dword from, to)
  42. {
  43.         dword dirbuf, fcount, filename;
  44.         int i, error, isdir;
  45.         char copy_from[4096], copy_in[4096];
  46.         char from2[4096], to2[4096];
  47.  
  48.         error = GetDir(#dirbuf, #fcount, from);
  49.         if (error) debug_error(from, error);
  50.        
  51.         if ((strcmp(to, "/sys")!=0) && (strcmp(to, "/tmp9/1")!=0))
  52.         {
  53.                 error = CreateDir(to);
  54.                 if (error) debug_error(to, error);
  55.         }
  56.         chrcat(to, '/');
  57.         chrcat(from, '/');
  58.  
  59.         for (i=0; i<fcount; i++)
  60.         {
  61.                 filename = i*304+dirbuf+72;
  62.  
  63.                 isdir = TestBit(ESDWORD[filename-40], 4);
  64.                 if (isdir)
  65.                 {
  66.                         if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
  67.                         strcpy(#from2, from);
  68.                         strcpy(#to2, to);
  69.  
  70.                         strcat(#from2, filename);
  71.                         strcat(#to2, filename);
  72.  
  73.                         CopyFolder(#from2, #to2);
  74.                 }
  75.                 else
  76.                 {
  77.                         strcpy(#copy_from, from);
  78.                         strcat(#copy_from, filename);
  79.                         strcpy(#copy_in, to);
  80.                         strcat(#copy_in, filename);
  81.  
  82.                         if (CheckEvent()==evReDraw) { DefineWindow("Installation Started", "Stop"); ShowProgress("Copying files..."); }
  83.                         ShowProgress(NULL);
  84.                         DrawBar(TEXTX, BLACK_H+50, Form.cwidth-TEXTX, 12, 0xFFFfff);
  85.                         WriteText(TEXTX, BLACK_H+50, 0x80, 0, filename);
  86.  
  87.                         error = CopyFile(#copy_from, #copy_in);
  88.                         if (error) error = CopyFile(#copy_from, #copy_in); // #2 :)
  89.                         if (error) debug_error(#copy_in, error);
  90.                 }
  91.         }
  92.         free(dirbuf);
  93. }
  94.  
  95.  
  96. unsigned char *ERROR_TEXT[]={
  97. "Code #0 - No error",
  98. "Error #1 - Base or partition of a hard disk is not defined",
  99. "Error #2 - Function isn't supported for this file system",
  100. "Error #3 - Unknown file system",
  101. "Error #4 - Reserved, is never returned",
  102. "Error #5 - File or folder not found",
  103. "Error #6 - End of file, EOF",
  104. "Error #7 - Pointer lies outside of application memory",
  105. "Error #8 - Too less disk space or FAT table is destroyed",
  106. "Error #9 - FAT table is destroyed",
  107. "Error #10 - Access denied",
  108. "Error #11 - Device error",
  109. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111. "Error #30 - Not enough memory",
  112. "Error #31 - File is not executable",
  113. "Error #32 - Too many processes",
  114. 0};
  115.  
  116. void debug_error(int path, error_number)
  117. {
  118.         char error[256];
  119.         if (path) debug(path);
  120.         if (error_number<0) error_number*=-1;  
  121.         if (error_number<33)
  122.         {
  123.                 strcpy(#error, ERROR_TEXT[error_number]);
  124.         }
  125.         else
  126.         {
  127.                 strcpy(#error, itoa(error_number));
  128.                 strcat(#error, " - Unknown error number O_o");
  129.         }
  130.         debug(#error);
  131. }
  132.  
  133. /*
  134. int files_num;
  135. void CalculateFilesNumber(dword from)
  136. {
  137.         dword dirbuf, fcount, filename;
  138.         int i, isdir, error;
  139.         char from2[4096];
  140.  
  141.         error = GetDir(#dirbuf, #fcount, from);
  142.         if (error) debug_error(from, error);
  143.         debugi(fcount);
  144.  
  145.         for (i=0; i<fcount; i++)
  146.         {
  147.                 filename = i*304+dirbuf+72;
  148.  
  149.                 isdir = TestBit(ESDWORD[filename-40], 4);
  150.                 if (!isdir)
  151.                 {
  152.                         files_num++;
  153.                         debug(filename);
  154.                 }
  155.                 else
  156.                 {
  157.                         if ( (!strcmp(filename, ".")) || (!strcmp(filename, "..")) ) continue;
  158.                         strcpy(#from2, from);
  159.                         chrcat(#from2, '/');
  160.                         strcat(#from2, filename);
  161.                         CalculateFilesNumber(#from2);
  162.                 }
  163.         }
  164.         free(dirbuf);
  165. }
  166.  
  167. int GetFilesNumber(dword pathz)
  168. {
  169.         files_num = 0;
  170.         CalculateFilesNumber(pathz);
  171.         return files_num;
  172. }
  173. */