diff options
author | David Crocker <dcrocker@eschertech.com> | 2018-02-04 22:38:29 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2018-02-04 22:38:29 +0300 |
commit | 1448121041393c9a878c3dd84ddd97dff2a4687f (patch) | |
tree | 23441e82f7705680779812bba25a953e6e5a2379 /src/Storage | |
parent | 7dc0079595cab16ebf1563b59c07e24b341c3efa (diff) |
Towards 1.21RC2
Refactored some string handling
Fixes for Duet 2M
Diffstat (limited to 'src/Storage')
-rw-r--r-- | src/Storage/FileStore.cpp | 19 | ||||
-rw-r--r-- | src/Storage/MassStorage.cpp | 4 | ||||
-rw-r--r-- | src/Storage/MassStorage.h | 4 |
3 files changed, 13 insertions, 14 deletions
diff --git a/src/Storage/FileStore.cpp b/src/Storage/FileStore.cpp index c47bcce9..bb8cd07a 100644 --- a/src/Storage/FileStore.cpp +++ b/src/Storage/FileStore.cpp @@ -63,21 +63,19 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) if (writing) { // Try to create the path of this file if we want to write to it - char filePathBuffer[FILENAME_LENGTH]; - StringRef filePath(filePathBuffer, FILENAME_LENGTH); + String<MaxFilenameLength> filePath; filePath.copy(location); - bool isVolume = isdigit(filePath[0]); - for (size_t i = 1; i < filePath.strlen(); i++) + size_t i = (isdigit(filePath[0]) && filePath[1] == ':') ? 2 : 0; + if (filePath[i] == '/') + { + ++i; + } + + while (i < filePath.strlen()) { if (filePath[i] == '/') { - if (isVolume) - { - isVolume = false; - continue; - } - filePath[i] = 0; if (!reprap.GetPlatform().GetMassStorage()->DirectoryExists(filePath.Pointer()) && !reprap.GetPlatform().GetMassStorage()->MakeDirectory(filePath.Pointer())) { @@ -86,6 +84,7 @@ bool FileStore::Open(const char* directory, const char* fileName, OpenMode mode) } filePath[i] = '/'; } + ++i; } // Also try to allocate a write buffer so we can perform faster writes diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp index 3e2e92c2..7a0e6afd 100644 --- a/src/Storage/MassStorage.cpp +++ b/src/Storage/MassStorage.cpp @@ -81,7 +81,7 @@ void MassStorage::Init() if (reply.strlen() != 0) { delay(3000); // Wait a few seconds so users have a chance to see this - reprap.GetPlatform().Message(UsbMessage, reply.Pointer()); + reprap.GetPlatform().MessageF(UsbMessage, "%s\n", reply.Pointer()); } } @@ -184,7 +184,7 @@ const char* MassStorage::CombineName(const char* directory, const char* fileName // Open a directory to read a file list. Returns true if it contains any files, false otherwise. bool MassStorage::FindFirst(const char *directory, FileInfo &file_info) { - TCHAR loc[FILENAME_LENGTH + 1]; + TCHAR loc[MaxFilenameLength + 1]; // Remove the trailing '/' from the directory name SafeStrncpy(loc, directory, ARRAY_SIZE(loc)); diff --git a/src/Storage/MassStorage.h b/src/Storage/MassStorage.h index ab7c6715..68f29058 100644 --- a/src/Storage/MassStorage.h +++ b/src/Storage/MassStorage.h @@ -13,7 +13,7 @@ struct FileInfo { bool isDirectory; - char fileName[FILENAME_LENGTH]; + char fileName[MaxFilenameLength]; uint32_t size; time_t lastModified; }; @@ -92,7 +92,7 @@ private: SdCardInfo info[NumSdCards]; DIR findDir; - char combinedName[FILENAME_LENGTH + 1]; + char combinedName[MaxFilenameLength + 1]; FileWriteBuffer *freeWriteBuffers; FileStore files[MAX_FILES]; |