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