home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / FILE_WRK.C < prev    next >
C/C++ Source or Header  |  1993-11-30  |  7KB  |  284 lines

  1. /*
  2.  * file containing the view file handling routines
  3.  */
  4.  
  5.  
  6. #include "viewdef.h"            /* definations for the viewer */
  7. #include "extern.h"        /* external declerations for viewer plus IJG includes */
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <dir.h>
  11. #include <dos.h>
  12. #include <conio.h>
  13. #include <alloc.h>
  14.  
  15.  
  16. #ifndef small_viewer
  17.  
  18. /*
  19.  * save the picture context info (contrast, tints, zoom ....)
  20.  * - just appends to the end of the file - duplicate entries are possibe and probable
  21.  */
  22.  
  23. void save_viewing_info()
  24. {
  25. char pic_file_path[file_name_len];
  26. FILE * file_in;
  27.  
  28. strcpy(view_setup_info.file_name, file_being_viewed);
  29. view_setup_info.red_tint = red_tint;
  30. view_setup_info.green_tint = green_tint;
  31. view_setup_info.blue_tint = blue_tint;
  32. view_setup_info.bright = color_scale;
  33. view_setup_info.contrast = contrast_scale;
  34. view_setup_info.offset_x = picture_x_offset;
  35. view_setup_info.offset_y = picture_y_offset;
  36. view_setup_info.shrink = shrink;
  37. view_setup_info.resolution = video_resolution;
  38. view_setup_info.video_size_x = x_max;
  39. view_setup_info.video_size_y = y_max;
  40.  
  41. strcpy(pic_file_path, file_path);
  42. strcat(pic_file_path, viewing_defaults_file);
  43.  
  44. if ( (file_in = fopen(pic_file_path, "ab")) != NULL)
  45.     fwrite(&view_setup_info, sizeof(view_setup_info), 1, file_in);
  46. fclose(file_in);
  47. }
  48.  
  49.  
  50.  
  51.  
  52. /*
  53.  * scan thru the given file to check for default viewing info (if names match)
  54.  * the last instance will be the correct one
  55.  */
  56. int find_picture_setup(FILE * file_in)
  57. {
  58. int find_it;
  59. struct view_info default_info;
  60.  
  61. find_it = 0;
  62.  
  63. while (!feof(file_in)){
  64.     fread(&view_setup_info, sizeof(struct view_info), 1, file_in);
  65.     if (stricmp(view_setup_info.file_name, file_being_viewed) == 0){
  66.         memcpy(&default_info, &view_setup_info, sizeof(view_setup_info));
  67.         find_it = 1;
  68.         }
  69.     }
  70.  
  71. if (find_it){    /* if we found it copy the stats to the global vars */
  72.     memcpy(&view_setup_info, &default_info, sizeof(view_setup_info));
  73.     red_tint = view_setup_info.red_tint;
  74.     green_tint = view_setup_info.green_tint;
  75.     blue_tint = view_setup_info.blue_tint;
  76.     color_scale = view_setup_info.bright;
  77.     contrast_scale = view_setup_info.contrast;
  78.     picture_x_offset = view_setup_info.offset_x;
  79.     picture_y_offset = view_setup_info.offset_y;
  80. /*
  81.     view_setup_info.shrink;
  82.     view_setup_info.resolution;
  83.     view_setup_info.video_size_x;
  84.     view_setup_info.video_size_y;
  85. */
  86.     }
  87.  
  88. return find_it;
  89. }
  90.  
  91.  
  92.  
  93.  
  94. /*
  95.  * delete a selected file from the default picture info
  96.  * - del all instances that match the name
  97.  * - since there may not be much memory do this by copying to a second file
  98.  *   and swap file names
  99.  */
  100.  
  101. void delete_from_setup_file(char * picture_name)
  102. {
  103. char pic_file_path[file_name_len],
  104.         path_out[file_name_len],
  105.         temp_str[file_name_len * 2];
  106. struct view_info default_info;
  107. FILE * file_in, * file_out;
  108.  
  109. strcpy(pic_file_path, file_path);
  110. strcat(pic_file_path, viewing_defaults_file);
  111.  
  112. strcpy(path_out, file_path);
  113. strcat(path_out, viewing_defaults_temp_file);
  114.  
  115. file_in = fopen(pic_file_path, "rb");
  116. file_out = fopen(path_out, "wb");
  117.  
  118. if ( file_in != NULL && file_out != NULL)
  119.     do{
  120.         fread(&default_info, sizeof(view_setup_info), 1, file_in);
  121.         if (strcmpi(default_info.file_name, picture_name) != 0 && (!feof(file_in)))
  122.             fwrite(&default_info, sizeof(view_setup_info), 1, file_out);
  123.         } while (!feof(file_in));
  124. fclose(file_in);
  125. fclose(file_out);
  126.  
  127. /* now delete the old and rename the new file */
  128. strcpy(temp_str, "del ");
  129. strcat(temp_str, file_path);
  130. strcat(temp_str, viewing_defaults_file);
  131. system(temp_str);
  132.  
  133. strcpy(temp_str, "rename ");
  134. strcat(temp_str, file_path);
  135. strcat(temp_str, viewing_defaults_temp_file);
  136. strcat(temp_str, " ");
  137. strcat(temp_str, viewing_defaults_file);
  138. system(temp_str);
  139. }
  140.  
  141. #else
  142. void save_viewing_info(){}
  143. int find_picture_setup(FILE * file_in){}
  144. void delete_from_setup_file(char * picture_name){}
  145. #endif
  146.  
  147.  
  148.  
  149. /*
  150.  * Get the list of files matching the file spec and sort into the name array
  151.  * of structs pointing to arrays of info  (whew)
  152.  *
  153.  *   Return the number of files read in.
  154.  */
  155.  
  156. void get_files(void)
  157. {
  158. int done,
  159.     index,
  160.     error_exit;        /* for an exit if run out of memory */
  161. struct ffblk ffblk;
  162. char search_path[80];
  163.  
  164.  
  165. init_file_struct();
  166.  
  167. if (file_info_head == NULL) error_exit = 1;        /* force exit if no memory for data records */
  168. else error_exit = 0;
  169.  
  170. /* now put the directory tree at the top of the list
  171.  * since the list is empty, and these are not sorted its easy
  172.  */
  173.  
  174. number_files = 0;
  175.  
  176. if (error_exit != 1){
  177.     strcpy(search_path, "[A]");        /* setup format for directory as printed */
  178.     if (defaults & show_drives)        /* now copy over good drives */
  179.         for (index = 0; index <= drive_list_length; index++)
  180.             if (drive_list[index] > 0){        /* we found a good one ?? */
  181.                 search_path[1] = drive_list[index];
  182.                 number_files += insert_in_place(search_path, 0, 0, NONE, 0, 0);
  183.                 }
  184.  
  185. index = number_files;    /* keep the head of the list */
  186.  
  187.     strcpy(search_path, file_path);
  188.     strcat(search_path, "*.*");
  189.     if (defaults & show_tree){
  190.         done = findfirst(search_path, &ffblk, FA_DIREC);
  191.         while (!done){
  192.             if (ffblk.ff_attrib & FA_DIREC)
  193.                 if (strlen(ffblk.ff_name) != 1 || ffblk.ff_name[0] != '.'){
  194.                     number_files += insert_in_place(ffblk.ff_name, 0, 0, FF_NAME, index, 0);
  195.                     }
  196.             done = findnext(&ffblk);
  197.             }
  198.         }
  199.     }
  200.  
  201. index = number_files;
  202.  
  203. index = 0;        /* repeat for all file masks */
  204. do{
  205.     strcpy(search_path, file_path);
  206.     strcat(search_path, file_masks[index]);
  207.  
  208.     done = findfirst(search_path, &ffblk, FA_SYSTEM);
  209.     while (!done && !error_exit){
  210.         if (ffblk.ff_fsize == 0) ffblk.ff_fsize = 1;        /* default to some minimum value */
  211.         number_files += insert_in_place(ffblk.ff_name, ffblk.ff_fsize, ffblk.ff_fdate, sort_mode, index, 0);
  212.         done = findnext(&ffblk);
  213.         }
  214.     index++;
  215.     } while (file_masks[index][0] != 0 && index < max_file_masks);
  216.  
  217.  
  218. if (first_file > number_files) first_file = 0;        /* setup current file pointer */
  219. }
  220.  
  221.  
  222.  
  223. /* change the assigned drive
  224.  * set the path to the current for that drive
  225.  * pass in the letter of the drive wanted
  226.  */
  227.  
  228. void change_drive(char drive)
  229. {
  230. int i;
  231.  
  232. if (drive - 'A' < max_drives){
  233.     strcpy(file_path, "C:\\");
  234.     file_path[0] = drive;
  235.     getcurdir(drive - 'A' + 1, file_path + 3);
  236.     if (strlen(file_path) > 3)   /* watch out for root because its X:/ already */
  237.     strcat(file_path, "\\");
  238.  
  239.     get_files();
  240.     }
  241. }
  242.  
  243.  
  244.  
  245. /*
  246.  * check to see if the 4DOS file (hidden) DESCRIPT.ION exists and
  247.  *    if so see if we can find the picture description
  248.  *
  249.  * picture_description is the string to return the info in (max file_name_len bytes)
  250.  */
  251.  
  252. void try_4_DOS(char * picture_description)
  253. {
  254. int find_it, i;
  255. FILE * file_in;
  256. char temp_str[file_name_len];
  257. char * name_str;
  258.  
  259. strcpy(temp_str, file_path);
  260. strcat(temp_str, "DESCRIPT.ION");
  261.  
  262. strcpy(picture_description, "");
  263.  
  264. if( (file_in = fopen(temp_str, "r")) == NULL) return;
  265.  
  266. find_it = 0;
  267.  
  268. while (!feof(file_in) && find_it == 0){
  269.     fgets(temp_str, file_name_len, file_in);
  270.     i = 0;
  271.     while(temp_str[i] != ' ' && temp_str[i] != 0 && i < file_name_len) i++;
  272.     if (i < strlen(temp_str)){
  273.         temp_str[strlen(temp_str) - 1] = 0;
  274.         name_str = &temp_str[i + 1];    /* mark start of comment */
  275.         temp_str[i] = 0;                    /* mark end of file name */
  276.         if (stricmp(temp_str, file_being_viewed) == 0)
  277.             find_it = 1;
  278.         }
  279.     }
  280.  
  281. if (find_it) strcpy(picture_description, name_str);
  282.  
  283. fclose(file_in);
  284. }