--- PstProcessing_update2.cpp Thu Mar 17 12:27:23 2016
+++ PstProcessing_HaRT.cpp Thu Mar 17 21:17:45 2016
@@ -18,13 +18,16 @@
}
}
-static wstring GetDupTestFilename(wstring &baseName, int dupCounter)
+static wstring GetDupTestFilename(wstring &baseName, int dupCounter, int noNameCounter)
{
wchar_t testName[MAX_PATH] = {0};
if (dupCounter > 0)
swprintf_s(testName, MAX_PATH, L"%s[%d].eml", baseName.c_str(), dupCounter);
else
swprintf_s(testName, MAX_PATH, L"%s.eml", baseName.c_str());
+
+ if(!*testName) // swprintf_s() failed (e.g. if baseName contained garbage)
+ swprintf_s(testName, MAX_PATH, L"Message%05d[%d].eml", noNameCounter, dupCounter);
return testName;
}
@@ -49,7 +52,8 @@
if (m.has_subject())
{
wstring subj = m.get_subject();
- if (subj.length() > 200) subj.erase(200);
+ if (subj.length() > 200)
+ subj.erase(200);
strBaseFileName = subj;
}
else
@@ -64,21 +68,22 @@
while (true)
{
bool dupFound = false;
- wstring testName = GetDupTestFilename(strBaseFileName, dupCounter);
+ wstring testName = GetDupTestFilename(strBaseFileName, dupCounter, NoNameCounter);
for (auto it = fileInfoObj->Entries.begin(); it != fileInfoObj->Entries.end(); it++)
{
const PstFileEntry& prevEntry = *it;
if ((prevEntry.Folder == parentPath) && (prevEntry.Name == testName))
{
dupFound = true;
+ break;
}
}
- if (!dupFound) break;
-
+ if (!dupFound)
+ break;
dupCounter++;
}
- wstring strFileName = GetDupTestFilename(strBaseFileName, dupCounter);
+ wstring strFileName = GetDupTestFilename(strBaseFileName, dupCounter, NoNameCounter);
PstFileEntry fentry;
fentry.Type = fileInfoObj->ExpandEmlFile ? ETYPE_FOLDER : ETYPE_EML;