EjectOSD::EjectOSD() : OSD(L"3RVX-EjectDispatcher"), _mWnd(L"3RVX-EjectOSD", L"3RVX-EjectOSD") { SkinManager *skin = SkinManager::Instance(); _mWnd.BackgroundImage(skin->EjectOSD()->background); _mWnd.EnableGlass(skin->EjectOSD()->mask); _mWnd.Update(); OSD::InitMeterWnd(_mWnd); DWORD drives = GetLogicalDrives(); DWORD msb = log2(drives); for (DWORD i = 0; i < msb; ++i, drives >>= 1) { if (drives & 0x1) { wchar_t letter = (wchar_t) i + 65; CLOG(L"Drive: %c", letter); wchar_t buf[256] = { 0 }; std::wstring name = std::wstring(1, letter) + L":\\"; QCLOG(L"type: %d", GetDriveType(name.c_str())); int result = GetVolumeInformation(name.c_str(), buf, 256, NULL, NULL, NULL, NULL, NULL); QCLOG(L"%s", buf); QCLOG(L"result %d", result); Logger::LogLastError(); } } }
LanguageTranslator::LanguageTranslator(std::wstring langFileName) { CLOG(L"Loading language XML: %s", langFileName.c_str()); FILE *fp; _wfopen_s(&fp, langFileName.c_str(), L"rb"); if (fp == NULL) { CLOG(L"Failed to open file!"); return; } tinyxml2::XMLError result = _xml.LoadFile(fp); if (result != tinyxml2::XMLError::XML_SUCCESS) { CLOG(L"Failed to read language file!"); return; } _root = _xml.GetDocument()->FirstChildElement("translation"); if (_root == NULL) { return; } /* _author = StringUtils::Widen(_root->Attribute("author", "")); */ tinyxml2::XMLElement *trans = _root->FirstChildElement("language"); if (trans == NULL) { CLOG(L"No <language> tag."); return; } CLOG(L"Loading translation header"); _name = StringUtils::Widen(trans->Attribute("name")); _id = StringUtils::Widen(trans->Attribute("id")); if (_name == L"" || _id == L"") { CLOG(L"whoops"); } QCLOG(L"Language name: %s", _name.c_str()); QCLOG(L"Locale identifier: %s", _id.c_str()); const char *regions = trans->Attribute("regions"); if (regions != NULL) { std::string region; std::istringstream ss(regions); while (std::getline(ss, region, ',')) { std::wstring regionStr = StringUtils::Widen(region); _regions.push_back(regionStr); QCLOG(L"Region: %s", regionStr.c_str()); } } }
void Settings::Load() { /* First, clean up (if needed) */ delete _translator; _translator = NULL; _file = SettingsFile(); CLOG(L"Loading settings: %s", _file.c_str()); FILE *fp; _wfopen_s(&fp, _file.c_str(), L"rb"); if (fp == NULL) { QCLOG(L"Failed to open file!"); LoadEmptySettings(); return; } tinyxml2::XMLError result = _xml.LoadFile(fp); fclose(fp); if (result != tinyxml2::XMLError::XML_SUCCESS) { LoadEmptySettings(); return; } _root = _xml.GetDocument()->FirstChildElement("settings"); if (_root == NULL) { Error::ErrorMessage(Error::GENERR_MISSING_XML, L"<settings>"); LoadEmptySettings(); return; } }
void LanguageTranslator::LoadTranslations() { if (_root == NULL) { return; } tinyxml2::XMLElement *string = _root->FirstChildElement("string"); for (; string != NULL; string = string->NextSiblingElement()) { const char *originalText = NULL; const char *translatedText = NULL; tinyxml2::XMLElement *orig = string->FirstChildElement("original"); if (orig) { originalText = orig->GetText(); } tinyxml2::XMLElement *trans = string->FirstChildElement("translation"); if (trans) { translatedText = trans->GetText(); } if (originalText && translatedText) { std::wstring origStr = StringUtils::Widen(originalText); std::wstring transStr = StringUtils::Widen(translatedText); if (_translations.find(origStr) != _translations.end()) { CLOG(L"WARNING: Duplicate translation found!"); QCLOG(L"[%s] -> [%s]", origStr.c_str(), transStr.c_str()); return; } _translations[origStr] = transStr; } } }
std::list<std::wstring> General::FindLanguages(std::wstring dir) { std::list<std::wstring> languages; WIN32_FIND_DATA ffd; HANDLE hFind; CLOG(L"Finding language translations in: %s", dir.c_str()); dir += L"\\*.xml"; hFind = FindFirstFile(dir.c_str(), &ffd); if (hFind == INVALID_HANDLE_VALUE) { CLOG(L"FindFirstFile() failed"); return languages; } do { std::wstring fName(ffd.cFileName); if (fName.at(0) == L'.') { continue; } if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } QCLOG(L"%s", fName.c_str()); languages.push_back(fName); } while (FindNextFile(hFind, &ffd)); FindClose(hFind); return languages; }
std::list<std::wstring> General::FindSkins(std::wstring dir) { std::list<std::wstring> skins; WIN32_FIND_DATA ffd; HANDLE hFind; CLOG(L"Finding skins in: %s", dir.c_str()); dir += L"\\*"; hFind = FindFirstFile(dir.c_str(), &ffd); if (hFind == INVALID_HANDLE_VALUE) { CLOG(L"FindFirstFile() failed"); return skins; } do { std::wstring fName(ffd.cFileName); if (fName.at(0) == L'.') { continue; } QCLOG(L"%s", fName.c_str()); skins.push_back(fName); } while (FindNextFile(hFind, &ffd)); FindClose(hFind); return skins; }
SkinInfo::SkinInfo(std::wstring skinFile) : _skinFile(skinFile) { CLOG(L"Loading skin XML: %s", _skinFile.c_str()); /* Remove the '/skin.xml' portion from the file name to get the dir name. */ std::wstring xmlName = std::wstring(Settings::SKIN_XML); _skinDir = _skinFile.substr(0, _skinFile.length() - (xmlName.length() + 1)); FILE *fp; _wfopen_s(&fp, _skinFile.c_str(), L"rb"); if (fp == NULL) { QCLOG(L"Failed to open file!"); return; } tinyxml2::XMLError result = _xml.LoadFile(fp); fclose(fp); if (result != tinyxml2::XMLError::XML_SUCCESS) { if (result == tinyxml2::XMLError::XML_ERROR_FILE_NOT_FOUND) { Error::ErrorMessageDie(SKINERR_INVALID_SKIN); } throw std::logic_error("Failed to read XML file!"); } _root = _xml.GetDocument()->FirstChildElement("skin"); if (_root == NULL) { throw std::runtime_error("Could not find root XML element"); } }
void Settings::CreateSettingsDir() { std::wstring settingsDir = SettingsDir(); CLOG(L"Creating settings directory: %s", settingsDir.c_str()); settingsDir = L"\\\\?\\" + settingsDir; /* Use long file path (\\?\) */ BOOL result = CreateDirectory(settingsDir.c_str(), NULL); if (result == FALSE) { if (GetLastError() == ERROR_ALREADY_EXISTS) { QCLOG(L"Directory already exists."); return; } if (GetLastError() == ERROR_PATH_NOT_FOUND) { QCLOG(L"Path not found!"); // TODO: error message? } } }
void NumberStrip::Draw(Gdiplus::Bitmap *buffer, Gdiplus::Graphics *graphics) { int units = CalcUnits(); int perc = units * (100 / _units); int digits[] = { perc % 10, (perc / 10) % 10, perc / 100, }; int chars = 1; if (digits[1] > 0) { chars = 2; } else if (digits[2] > 0) { chars = 3; } int drawX = _charWidth * 2; if (_align == Gdiplus::StringAlignmentNear) { drawX = (chars - 1) * _charWidth; } else if (_align == Gdiplus::StringAlignmentFar) { drawX = (_charWidth * 2) - ((3 - chars) * (_charWidth / 2)); } for (int i = 0, x = drawX; i < chars; ++i, x -= _charWidth) { int digit = digits[i]; QCLOG(L"Drawing digit [%d]; x-offset: %d", digit, _rect.X + x); Gdiplus::Rect destRect(_rect.X + x, _rect.Y, _charWidth, _rect.Height); graphics->DrawImage(_bitmap, destRect, 0, digit * _rect.Height, _charWidth, _rect.Height, Gdiplus::UnitPixel, NULL, NULL, NULL); } UpdateDrawnValues(); }