This commit is contained in:
Birunthan Mohanathas 2013-01-27 12:58:16 +02:00
parent 638aaa137d
commit 8ecc6105e4
2 changed files with 15 additions and 41 deletions

View File

@ -55,8 +55,12 @@
<ResourceCompile Include="PluginQuote.rc" /> <ResourceCompile Include="PluginQuote.rc" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\Common\StringUtil.cpp" />
<ClCompile Include="Quote.cpp" /> <ClCompile Include="Quote.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Common\StringUtil.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -21,8 +21,9 @@
#include <vector> #include <vector>
#include <time.h> #include <time.h>
#include <shlwapi.h> #include <shlwapi.h>
#include "../../Library/Export.h" // Rainmeter's exported functions #include "../API/RainmeterAPI.h"
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point #include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
#include "../../Common/StringUtil.h"
#define BUFFER_SIZE 4096 #define BUFFER_SIZE 4096
@ -34,40 +35,6 @@ struct MeasureData
std::wstring value; std::wstring value;
}; };
std::string ConvertToAscii(LPCTSTR str)
{
std::string szAscii;
if (str && *str)
{
int strLen = (int)wcslen(str);
int bufLen = WideCharToMultiByte(CP_ACP, 0, str, strLen, NULL, 0, NULL, NULL);
if (bufLen > 0)
{
szAscii.resize(bufLen);
WideCharToMultiByte(CP_ACP, 0, str, strLen, &szAscii[0], bufLen, NULL, NULL);
}
}
return szAscii;
}
std::wstring ConvertToWide(LPCSTR str)
{
std::wstring szWide;
if (str && *str)
{
int strLen = (int)strlen(str);
int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
if (bufLen > 0)
{
szWide.resize(bufLen);
MultiByteToWideChar(CP_ACP, 0, str, strLen, &szWide[0], bufLen);
}
}
return szWide;
}
void ScanFolder(std::vector<std::wstring>& files, std::vector<std::wstring>& filters, bool bSubfolders, const std::wstring& path) void ScanFolder(std::vector<std::wstring>& files, std::vector<std::wstring>& filters, bool bSubfolders, const std::wstring& path)
{ {
// Get folder listing // Get folder listing
@ -268,6 +235,9 @@ PLUGIN_EXPORT double Update(void* data)
// It's ascii // It's ascii
char* aBuffer = (char*)buffer; char* aBuffer = (char*)buffer;
const std::string separator = StringUtil::Narrow(measure->separator);
const char* separatorSz = separator.c_str();
// Read until we find the first separator // Read until we find the first separator
char* sepPos1 = NULL; char* sepPos1 = NULL;
char* sepPos2 = NULL; char* sepPos2 = NULL;
@ -276,7 +246,7 @@ PLUGIN_EXPORT double Update(void* data)
size_t len = fread(buffer, sizeof(char), BUFFER_SIZE, file); size_t len = fread(buffer, sizeof(char), BUFFER_SIZE, file);
aBuffer[len] = 0; aBuffer[len] = 0;
sepPos1 = strstr(aBuffer, ConvertToAscii(measure->separator.c_str()).c_str()); sepPos1 = strstr(aBuffer, separatorSz);
if (sepPos1 == NULL) if (sepPos1 == NULL)
{ {
// The separator wasn't found // The separator wasn't found
@ -292,7 +262,7 @@ PLUGIN_EXPORT double Update(void* data)
} }
else else
{ {
sepPos1 += measure->separator.size(); sepPos1 += separator.size();
} }
} }
while (sepPos1 == NULL); while (sepPos1 == NULL);
@ -300,19 +270,19 @@ PLUGIN_EXPORT double Update(void* data)
// Find the second separator // Find the second separator
do do
{ {
sepPos2 = strstr(sepPos1, ConvertToAscii(measure->separator.c_str()).c_str()); sepPos2 = strstr(sepPos1, separatorSz);
if (sepPos2 == NULL) if (sepPos2 == NULL)
{ {
// The separator wasn't found // The separator wasn't found
if (feof(file)) if (feof(file))
{ {
// End of file reached -> read the rest // End of file reached -> read the rest
measure->value += ConvertToWide(sepPos1); measure->value += StringUtil::Widen(sepPos1);
break; break;
} }
else else
{ {
measure->value += ConvertToWide(sepPos1); measure->value += StringUtil::Widen(sepPos1);
// else continue reading // else continue reading
size_t len = fread(buffer, sizeof(char), BUFFER_SIZE, file); size_t len = fread(buffer, sizeof(char), BUFFER_SIZE, file);
@ -328,7 +298,7 @@ PLUGIN_EXPORT double Update(void* data)
} }
// Read until we find the second separator // Read until we find the second separator
measure->value += ConvertToWide(sepPos1); measure->value += StringUtil::Widen(sepPos1);
} }
} }
while (sepPos2 == NULL); while (sepPos2 == NULL);