Check file is now optional, try-catch in file write, updated todo
This commit is contained in:
55
nCard0.cpp
55
nCard0.cpp
@@ -1,12 +1,11 @@
|
||||
/*
|
||||
Info: Network based card0 changer. Will listen on a socket specified by user for a card0 information.
|
||||
Compiler: MinGW g++ 6.3.0 (Windows)
|
||||
MinGW g++ 5.3.1 (Ubuntu 16.04)
|
||||
Compiler: MinGW g++ 5.3.1 (Ubuntu 16.04)
|
||||
Flags: -std=c++11 -static-libgcc -static-libstdc++ -lws2_32
|
||||
Run ex: nCard0.exe -p1="G:\card0.txt" -p2="H:\card0.txt" -c1="G:\check.txt" -c2="H:\check.txt" -p="4500"
|
||||
|
||||
TODO:
|
||||
Add way to debug to log file
|
||||
Dump debug message to log file
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
@@ -69,7 +68,7 @@ int main (int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if(card_p1 == "" || check_p1 == "" || port < 1 || port > 65535) // failed validation
|
||||
if(card_p1 == "" || port < 1 || port > 65535) // failed validation
|
||||
exampleMessage();
|
||||
|
||||
debugOutput("Card P1:\t" + card_p1 + "\n");
|
||||
@@ -247,27 +246,35 @@ int main (int argc, char* argv[])
|
||||
if(buffer[0] == '1') //p1
|
||||
{
|
||||
debugOutput("Looking for P1 check file in: " + check_p1 + "... ");
|
||||
if(checkExist(check_p1))
|
||||
if(check_p1 != "" && checkExist(check_p1))
|
||||
{
|
||||
debugOutput("Found!\n");
|
||||
|
||||
debugOutput("Found!\n");
|
||||
overwriteCard(buffer, card_p1);
|
||||
}
|
||||
else
|
||||
else if(check_p1 == "") // forced overwrite without check file
|
||||
{
|
||||
debugOutput("Not found!\nSkipping overwrite of card0\n");
|
||||
debugOutput("No check file found!\nOverwriting card regardless\n");
|
||||
}
|
||||
else // refuse overwrite
|
||||
{
|
||||
debugOutput("No check file found!\nSkipping overwrite of card0\n");
|
||||
}
|
||||
}
|
||||
else //p2
|
||||
{
|
||||
debugOutput("Looking for P2 check file in: " + check_p2 + "... ");
|
||||
if(checkExist(check_p2))
|
||||
if(check_p2 != "" && checkExist(check_p2))
|
||||
{
|
||||
debugOutput("Found!\n");
|
||||
|
||||
overwriteCard(buffer, card_p2);
|
||||
}
|
||||
else
|
||||
else if(check_p2 == "") // forced overwrite without check file
|
||||
{
|
||||
debugOutput("No check file found!\nOverwriting card regardless\n");
|
||||
overwriteCard(buffer, card_p2);
|
||||
}
|
||||
else // refuse overwrite
|
||||
{
|
||||
debugOutput("Not found!\nSkipping overwrite of card0\n");
|
||||
}
|
||||
@@ -275,7 +282,8 @@ int main (int argc, char* argv[])
|
||||
}
|
||||
else // invalid data
|
||||
{
|
||||
debugOutput("Invalid data recieved: " + buffer);
|
||||
std::string bufferS(buffer); // fix this ghetto way to send the data
|
||||
debugOutput("Invalid data recieved: " + bufferS);
|
||||
}
|
||||
//send( s , "recieved" , valread , 0 );
|
||||
|
||||
@@ -327,15 +335,24 @@ bool overwriteCard(std::string buffer, std::string location)
|
||||
debugOutput("Card data: " + card + "\n");
|
||||
|
||||
// try to write card file
|
||||
std::ofstream cardFile(location);
|
||||
if(cardFile.is_open())
|
||||
try
|
||||
{
|
||||
cardFile << card;
|
||||
cardFile.close();
|
||||
debugOutput("Successfully written card number to: " + location + "\n");
|
||||
std::ofstream cardFile(location);
|
||||
if(cardFile.is_open())
|
||||
{
|
||||
cardFile << card;
|
||||
cardFile.close();
|
||||
debugOutput("Successfully written card number to: " + location + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
debugOutput("Unable to write to card in: " + location + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (std::ofstream::failure &e)
|
||||
{
|
||||
debugOutput("Unable to write to card in: " + location + "\n");
|
||||
std::string errorMsg(e.what());
|
||||
debugOutput("An error occured when trying to write file: " + errorMsg);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user