fileops.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // fileops.cpp
  20. //
  21. #include "stdAfx.h"
  22. #include "fileops.h"
  23. int FileExists ( const char *filename )
  24. {
  25. int fa = FileAttribs ( filename );
  26. return ! ( (fa == FA_NOFILE) || (fa & FA_DIRECTORY ));
  27. }
  28. int FileAttribs ( const char *filename )
  29. {
  30. WIN32_FIND_DATA fi;
  31. HANDLE handle;
  32. int fa = FA_NOFILE;
  33. handle = FindFirstFile ( filename, &fi );
  34. if ( handle != INVALID_HANDLE_VALUE )
  35. {
  36. if ( fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  37. {
  38. fa |= FA_DIRECTORY;
  39. }
  40. if ( fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY )
  41. {
  42. fa |= FA_READONLY;
  43. }
  44. else
  45. {
  46. fa |= FA_WRITEABLE;
  47. }
  48. FindClose ( handle );
  49. }
  50. return fa;
  51. }
  52. static void make_bk_name ( char *bkname, const char *filename )
  53. {
  54. char *ext, *ext1;
  55. strcpy ( bkname, filename );
  56. ext = strchr ( filename, '.' );
  57. ext1 = strchr ( bkname, '.' );
  58. if ( ext )
  59. {
  60. strcpy ( ext1, "_back_up" );
  61. strcat ( ext1, ext );
  62. }
  63. else
  64. {
  65. strcat ( bkname, "_back_up" );
  66. }
  67. }
  68. void MakeBackupFile ( const char *filename )
  69. {
  70. char bkname[256];
  71. make_bk_name ( bkname, filename );
  72. CopyFile ( filename, bkname, FALSE );
  73. }
  74. void RestoreBackupFile ( const char *filename )
  75. {
  76. char bkname[256];
  77. make_bk_name ( bkname, filename );
  78. if ( FileExists ( bkname ))
  79. {
  80. CopyFile ( bkname, filename, FALSE );
  81. }
  82. }