-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
165 lines (129 loc) · 4.5 KB
/
main.cpp
File metadata and controls
165 lines (129 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef _TESTAPP_CPP
#define _TESTAPP_CPP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define _CRT_SECURE_NO_WARNINGS //Disables strcpy() security warning on Microsoft compilers.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Windows.H>
#include <cStdIO>
#include <cStdLib>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "CCRC32.H"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
void splitstring(string str, string separator, string &first, string &second);
int main(int iArg, char *sArg[])
{
char sSourceFile[MAX_PATH];
memset(sSourceFile, 0, sizeof(sSourceFile));
if(iArg > 1)
{
//Get the passed in file name.
strcpy(sSourceFile, sArg[1]);
}
else{
//No file name was passed in, ask the user for the file name.
cout << "Enter a file name: ";
cin >> sSourceFile;
}
if(strlen(sSourceFile) > 0) //Do we have a file name?
{
string line, file, crc;
int good = 0, bad = 0;
ifstream sfv (sSourceFile);
if (sfv.is_open())
{
while ( sfv.good() )
{
getline (sfv,line);
if (line == "") continue;
if (";" == line.substr(0, 1)) continue;
splitstring(line, " ", file, crc);
CCRC32 MyCRC32;
MyCRC32.Initialize(); //Only have to do this once.
unsigned long ulCRC = 0, check = 0;
if(MyCRC32.FileCRC(file.c_str(), &ulCRC))
{
stringstream ss;
stringstream sf(crc);
ss << hex << ulCRC;
sf.clear();
sf.str(crc);
if ( ss.str().length() == 7 )
{
string temp;
ss >> temp;
ss.clear();
ss.str("");
ss << 0 << temp;
}
cout << "Source File: " << ss.str() << endl;
cout << "SFV file: " << sf.str() << endl;
if ( ss.str() == sf.str() )
{
good++;
cout << "GOOD!" << endl;
}
else
{
bad++;
cout << "BAD!" << endl;
string oldname = file;
string newname = file;
newname += "_BAD_OR_INCOMPLETE";
int result = rename( oldname.c_str() , newname.c_str() );
if ( result == 0)
puts ("File renamed");
else
perror("Error renaming file");
}
ss.clear();
sf.clear();
}
else
{
cout << "File not found or access denied.\n";
}
ulCRC = 0;
}
sfv.close();
}
cout << "Good files: "<< good << endl << "Bad files: " << bad << endl;
}
else{
cout << "No input file was specified.\n";
}
system("pause");
return 0;
}
void splitstring(string str, string separator, string &first, string &second)
{
size_t i = str.find(separator);
if(i != string::npos)
{
size_t y = 0;
if(!str.empty())
{
first=""; second="";
while(y != i)
{
first += str[y++];
}
y += separator.length();
while(y != str.length())
{
second += str[y++];
}
}
}
else
{
first = str;
second = "";
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#endif