Skip to content

Commit

Permalink
added file exists check
Browse files Browse the repository at this point in the history
  • Loading branch information
rnayabed committed Jun 2, 2023
1 parent 8541cbc commit 9cd70f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ GNU General Public License for more details.

cmake_minimum_required(VERSION 3.5)

project(vegadude LANGUAGES CXX)
set(VERSION 1.0)

project(vegadude
VERSION ${VERSION}
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -27,7 +31,8 @@ add_executable(vegadude
xmodem.h xmodem.cpp)

add_compile_definitions(
VERSION=1.0
VERSION=${VERSION}
GIT_REPOSITORY="https://github.com/rnayabed/vegadude"
LICENSE="https://github.com/rnayabed/vegadude/blob/master/LICENSE"
ARIES_XMODEM_BLOCK_SIZE=128
)
Expand Down
4 changes: 3 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ int main(int argc, char** argv)
return -1;
}

Logger::get() << "vegadude " << VERSION << Logger::NewLine << Logger::NewLine
Logger::get() << "vegadude " << VERSION << Logger::NewLine
<< "<" << GIT_REPOSITORY << ">" << Logger::NewLine
<< Logger::NewLine
<< "================================================" << Logger::NewLine
<< "Device Path: " << targetPath << Logger::NewLine
<< "Binary Path: " << binaryPath << Logger::NewLine
Expand Down
8 changes: 8 additions & 0 deletions xmodem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ std::string XModem::errorStr()
return "None";
case DEVICE_RELATED:
return "Device related error";
case FILE_DOES_NOT_EXIST:
return "File does not exist";
case FILE_OPEN_FAILED:
return "Failed to open file";
case MAX_RETRY_SURPASSED:
Expand All @@ -61,6 +63,12 @@ bool XModem::upload(const std::filesystem::path &filePath, const bool& startAfte
size_t currentBlock;
int32_t currentTry = 0;

if (!std::filesystem::exists(filePath))
{
m_error = Error::FILE_DOES_NOT_EXIST;
return false;
}

size_t fileSize = std::filesystem::file_size(filePath);
size_t noOfBlocks = std::ceil(float(fileSize) / float(m_blockSize));

Expand Down
1 change: 1 addition & 0 deletions xmodem.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class XModem
{
NONE,
DEVICE_RELATED,
FILE_DOES_NOT_EXIST,
FILE_OPEN_FAILED,
MAX_RETRY_SURPASSED,
CANCELLED
Expand Down

0 comments on commit 9cd70f3

Please sign in to comment.