Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changes for 3.1.0:
* Fixed issue #72: Move the code FileManager class generation code into its own IGenerator implementation.
* Fixed issue #74: Invalid generated output file name: index.cpptml.cpp.
* Fixed issue #77: Refactor generating code to use full file templates with markers.
* Fixed issue #78: Move duplicated enums from main.cpp to enums.h.


Changes for 3.0.1:
Expand Down
53 changes: 53 additions & 0 deletions src/bin2cpp/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,59 @@ namespace bin2cpp
return BIN2CPP_VERSION;
}

const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code)
{
switch ( error_code )
{
case APP_ERROR_SUCCESS:
return "Success";
break;
case APP_ERROR_MISSINGARGUMENTS:
return "Missing arguments";
break;
case APP_ERROR_INPUTFILENOTFOUND:
return "Unable to open input file";
break;
case APP_ERROR_UNABLETOCREATEOUTPUTFILES:
return "Unable to create output files";
break;
case APP_ERROR_TOOMANYARGUMENTS:
return "Too many arguments";
break;
case APP_ERROR_INPUTDIRNOTFOUND:
return "Input directory not found";
break;
case AAP_ERROR_NOTSUPPORTED:
return "Operation not supported";
break;
case APP_ERROR_OPERATIONHASFAILED:
return "Operation has failed";
break;
case APP_ERROR_INVALIDVALUE:
return "Invalid value";
break;
default:
return "Unknown error";
};
}

const char* getUpdateModeText(const FILE_UPDATE_MODE& mode)
{
switch ( mode )
{
case WRITING:
return "Writing";
case UPDATING:
return "Updating";
case OVERWRITING:
return "Overwriting";
case SKIPPING:
return "Skipping";
default:
return "Unknown";
};
}

uint64_t getOutputFileModifiedDate(const std::string & path)
{
uint64_t mod_time = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/bin2cpp/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ namespace bin2cpp
///</summary>
const char * getVersionString();

///<summary>
///Get the desription of the given application error code.
///</summary>
///<param name="error_code">The error code.</param>
///<return>Returns a string description of the given error code. Returns 'Unknown error' for unknown codes.<return>
const char* getErrorCodeDescription(const APP_ERROR_CODES& error_code);

///<summary>
///Get the desription of the given file update mode.
///</summary>
///<param name="mode">The file update mode.</param>
///<return>Returns a string description of the given file update mode. Returns 'Unknown' for unknown modes.<return>
const char* getUpdateModeText(const FILE_UPDATE_MODE& mode);

///<summary>
///Returns the modified date from an embedded file's c++ header/source file.
///Note that the function returns the number of seconds elapsed since epoch since Jan 1st 1970.
Expand Down
27 changes: 27 additions & 0 deletions src/bin2cpp/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@
namespace bin2cpp
{

///<summary>
///Error codes returned by the application
///</summary>
enum APP_ERROR_CODES
{
APP_ERROR_SUCCESS = 0,
APP_ERROR_MISSINGARGUMENTS,
APP_ERROR_INPUTFILENOTFOUND,
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
APP_ERROR_TOOMANYARGUMENTS,
APP_ERROR_INPUTDIRNOTFOUND,
AAP_ERROR_NOTSUPPORTED,
APP_ERROR_OPERATIONHASFAILED,
APP_ERROR_INVALIDVALUE,
};

///<summary>
///File update modes.
///</summary>
enum FILE_UPDATE_MODE
{
WRITING,
UPDATING,
OVERWRITING,
SKIPPING,
};

///<summary>
///Defines the different types of cpp encoding.
///</summary>
Expand Down
75 changes: 1 addition & 74 deletions src/bin2cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,12 @@
#include "rapidassist/process.h"
#include "rapidassist/timing.h"

#include "enums.h"
#include "common.h"
#include "wildcard.h"

using namespace bin2cpp;

enum APP_ERROR_CODES
{
APP_ERROR_SUCCESS = 0,
APP_ERROR_MISSINGARGUMENTS,
APP_ERROR_INPUTFILENOTFOUND,
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
APP_ERROR_TOOMANYARGUMENTS,
APP_ERROR_INPUTDIRNOTFOUND,
AAP_ERROR_NOTSUPPORTED,
APP_ERROR_OPERATIONHASFAILED,
APP_ERROR_INVALIDVALUE,
};

enum FILE_UPDATE_MODE
{
WRITING,
UPDATING,
OVERWRITING,
SKIPPING,
};

//default values
static const size_t DEFAULT_CHUNK_SIZE = 200;
static const char * DEFAULT_NAMESPACE_CPP = "bin2cpp";
Expand All @@ -84,59 +64,6 @@ static Dictionary output_files_dictionary; // unique values for output file nam
#define DIRECTORY_FILTER_SEPARATOR_STR ":"
static const char DIRECTORY_FILTER_SEPARATOR = DIRECTORY_FILTER_SEPARATOR_STR[0];

const char * getErrorCodeDescription(const APP_ERROR_CODES & error_code)
{
switch(error_code)
{
case APP_ERROR_SUCCESS:
return "Success";
break;
case APP_ERROR_MISSINGARGUMENTS:
return "Missing arguments";
break;
case APP_ERROR_INPUTFILENOTFOUND:
return "Unable to open input file";
break;
case APP_ERROR_UNABLETOCREATEOUTPUTFILES:
return "Unable to create output files";
break;
case APP_ERROR_TOOMANYARGUMENTS:
return "Too many arguments";
break;
case APP_ERROR_INPUTDIRNOTFOUND:
return "Input directory not found";
break;
case AAP_ERROR_NOTSUPPORTED:
return "Operation not supported";
break;
case APP_ERROR_OPERATIONHASFAILED:
return "Operation has failed";
break;
case APP_ERROR_INVALIDVALUE:
return "Invalid value";
break;
default:
return "Unknown error";
};
}

const char * getUpdateModeText(const FILE_UPDATE_MODE & mode)
{
switch(mode)
{
case WRITING:
return "Writing";
case UPDATING:
return "Updating";
case OVERWRITING:
return "Overwriting";
case SKIPPING:
return "Skipping";
default:
return "Unknown";
};
}

struct ARGUMENTS
{
bool help;
Expand Down
17 changes: 4 additions & 13 deletions test/bin2cpp_unittest/TestCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include "rapidassist/strings.h"
#include "rapidassist/timing.h"

#include "enums.h"

using namespace bin2cpp;

extern const std::string & gGeneratedFilesDir;
#ifdef _WIN32
const std::string & gGeneratedFilesDir = "generated_files\\";
Expand All @@ -46,19 +50,6 @@ extern const std::string & gGeneratedFilesDir;
}\
}

enum APP_ERROR_CODES
{
APP_ERROR_SUCCESS = 0,
APP_ERROR_MISSINGARGUMENTS,
APP_ERROR_INPUTFILENOTFOUND,
APP_ERROR_UNABLETOCREATEOUTPUTFILES,
APP_ERROR_TOOMANYARGUMENTS,
APP_ERROR_INPUTDIRNOTFOUND,
AAP_ERROR_NOTSUPPORTED,
APP_ERROR_OPERATIONHASFAILED,
APP_ERROR_INVALIDVALUE,
};

namespace TestCLIUtils
{
std::string getExpectedFilePath()
Expand Down