summaryrefslogtreecommitdiff
path: root/plugins/CurrencyRates/src/CreateFilePath.cpp
blob: 18a8896e9d146223fb599f4b87cf62fbfb4a1cc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "StdAfx.h"

static wchar_t InvalidSymbols[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };

static wchar_t replace_invalid_symbol(wchar_t chr)
{
	for (int i = 0; i < _countof(InvalidSymbols); ++i)
		if (chr == InvalidSymbols[i])
			return '_';

	return chr;
}

void prepare_name(tstring& rsName)
{
	std::transform(rsName.begin(), rsName.end(), rsName.begin(), boost::bind(replace_invalid_symbol, _1));
}

tstring CreateFilePath(const tstring& rsName)
{
	wchar_t szPath[_MAX_PATH];
	::GetModuleFileName(g_plugin.getInst(), szPath, _MAX_PATH);

	wchar_t* p = wcsrchr(szPath, '\\');
	if (p)
		*p = 0;

	tstring s(rsName);
	prepare_name(s);
	tostringstream o;
	o << szPath << L"\\CurrencyRates\\" << s;
	return o.str();
}