Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
fileops.cpp
Go to the documentation of this file.
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//
20// fileops.cpp
21//
22
23#include "stdAfx.h"
24#include "fileops.h"
25
26
27
28
29int FileExists ( const char *filename )
30{
31 int fa = FileAttribs ( filename );
32
33 return ! ( (fa == FA_NOFILE) || (fa & FA_DIRECTORY ));
34}
35
36
37int FileAttribs ( const char *filename )
38{
39 WIN32_FIND_DATA fi;
40 HANDLE handle;
41 int fa = FA_NOFILE;
42
43 handle = FindFirstFile ( filename, &fi );
44
45 if ( handle != INVALID_HANDLE_VALUE )
46 {
47 if ( fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
48 {
49 fa |= FA_DIRECTORY;
50 }
51 if ( fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY )
52 {
53 fa |= FA_READONLY;
54 }
55 else
56 {
57 fa |= FA_WRITEABLE;
58 }
59
60 FindClose ( handle );
61 }
62
63 return fa;
64}
65
66static void make_bk_name ( char *bkname, const char *filename )
67{
68 char *ext, *ext1;
69
70 strcpy ( bkname, filename );
71
72 ext = strchr ( filename, '.' );
73 ext1 = strchr ( bkname, '.' );
74
75 if ( ext )
76 {
77 strcpy ( ext1, "_back_up" );
78 strcat ( ext1, ext );
79 }
80 else
81 {
82 strcat ( bkname, "_back_up" );
83 }
84
85}
86
87void MakeBackupFile ( const char *filename )
88{
89 char bkname[256];
90
91 make_bk_name ( bkname, filename );
92
93 CopyFile ( filename, bkname, FALSE );
94
95}
96
97void RestoreBackupFile ( const char *filename )
98{
99 char bkname[256];
100
101 make_bk_name ( bkname, filename );
102
103 if ( FileExists ( bkname ))
104 {
105 CopyFile ( bkname, filename, FALSE );
106 }
107
108}
#define FALSE
Definition BaseType.h:113
void RestoreBackupFile(const char *filename)
Definition fileops.cpp:97
void MakeBackupFile(const char *filename)
Definition fileops.cpp:87
int FileExists(const char *filename)
Definition fileops.cpp:29
int FileAttribs(const char *filename)
Definition fileops.cpp:37