Skip to content

Commit

Permalink
Fixed name shorting to account for multiple dots
Browse files Browse the repository at this point in the history
  • Loading branch information
CherryPill committed May 26, 2017
1 parent b1c3918 commit aef747f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions crypto_md5/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@ void getFileNameFromPath(TCHAR *fullPath, TCHAR *fileName) {
TCHAR *shortenPath(TCHAR *path) {
static TCHAR shortenedPath[256] = {0};
TCHAR *lastPart = NULL;
TCHAR *extensionPart;
TCHAR *extensionPart[256] = {0};
_tcsncpy(shortenedPath, path, 4);
_tcscat(shortenedPath, _T(".."));
path+=4+1;
_tcstok(path, _T("."));
separateNameAndExt(path, extensionPart);
lastPart = path+_tcslen(path)-4;
_tcscat(shortenedPath, lastPart);
path = _tcstok(NULL, _T("."));
_tcscat(shortenedPath, _T("."));
_tcscat(shortenedPath, path);
_tcscat(shortenedPath, extensionPart);
memset(path, 0, sizeof(path));
return shortenedPath;
}
void separateNameAndExt(TCHAR *fullPath, TCHAR *ext) {
int c = _tcslen(fullPath)-1;
TCHAR *extLoc = fullPath+c;
TCHAR singleChar;
do {
singleChar = *extLoc;
if (singleChar == _T('.')) {
break;
}
--c;
extLoc = fullPath+c;
}while(extLoc!=fullPath);
_tcscpy(ext, extLoc);
fullPath[c] = _T('\0');
}
3 changes: 2 additions & 1 deletion crypto_md5/utility.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
void centerWindow(POINT*);
void getFileNameFromPath(TCHAR *fullPath, TCHAR *fileName);
TCHAR *shortenPath(TCHAR *);
TCHAR *shortenPath(TCHAR *);
void separateNameAndExt(TCHAR *fullPath, TCHAR *ext);

0 comments on commit aef747f

Please sign in to comment.