Skip to content

Commit

Permalink
bug fixed: locations with submenu not found
Browse files Browse the repository at this point in the history
  • Loading branch information
zodiacon committed Jun 17, 2023
1 parent 97e720a commit af02700
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 51 deletions.
42 changes: 16 additions & 26 deletions Installer/Installer.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_EE04FFDAA62949B3A8B2609A5B1883D7"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
}
"Configurations"
{
Expand All @@ -43,6 +37,14 @@
"PrivateKeyFile" = "8:"
"TimeStampServer" = "8:"
"InstallerBootstrapper" = "3:2"
"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"
{
"Enabled" = "11:TRUE"
"PromptEnabled" = "11:TRUE"
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
}
}
"Release"
{
Expand All @@ -59,6 +61,14 @@
"PrivateKeyFile" = "8:"
"TimeStampServer" = "8:"
"InstallerBootstrapper" = "3:2"
"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"
{
"Enabled" = "11:TRUE"
"PromptEnabled" = "11:TRUE"
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
}
}
}
"Deployable"
Expand Down Expand Up @@ -100,26 +110,6 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_EE04FFDAA62949B3A8B2609A5B1883D7"
{
"SourcePath" = "8:..\\x64\\Release\\KRegExp.sys"
"TargetName" = "8:KRegExp.sys"
"Tag" = "8:"
"Folder" = "8:_7721258380494D938FE03138DFDD2ADF"
"Condition" = "8:"
"Transitive" = "11:FALSE"
"Vital" = "11:FALSE"
"ReadOnly" = "11:FALSE"
"Hidden" = "11:FALSE"
"System" = "11:FALSE"
"Permanent" = "11:FALSE"
"SharedLegacy" = "11:FALSE"
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
}
"FileType"
{
Expand Down
54 changes: 33 additions & 21 deletions RegExp/LocationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool LocationManager::LoadFromRegistry(PCWSTR path) {
if (ERROR_SUCCESS != key.QueryStringValue(L"Locations", data.get(), &chars))
return false;

_items.clear();
m_Items.clear();
for (auto p = data.get(); *p; ) {
auto semi = wcschr(p, L';');
if (semi == nullptr)
Expand All @@ -34,15 +34,18 @@ bool LocationManager::LoadFromRegistry(PCWSTR path) {
CString path(semi + 1, (int)(cr - semi - 1));
if (name.IsEmpty())
name = path;
_items.insert({ name, path });
//if (name.Left(4) != L"HKEY")
// name = name.Mid(name.Find(L"/") + 1);

m_Items.insert({ name, path });
p = cr + 1;
}

return true;
}

bool LocationManager::SaveToRegistry(PCWSTR path) const {
if (_items.empty())
if (m_Items.empty())
return true;

path = GetPath(path);
Expand All @@ -55,7 +58,7 @@ bool LocationManager::SaveToRegistry(PCWSTR path) const {
return false;

CString text;
for (const auto& [name, value] : _items) {
for (const auto& [name, value] : m_Items) {
text += name + L";" + value + L"\n";
}
return ERROR_SUCCESS == key.SetStringValue(L"Locations", text);
Expand All @@ -73,7 +76,7 @@ bool LocationManager::LoadFromFile(PCWSTR path) {
auto data = file.ReadSection(L"Locations");
for (auto& text : data) {
int n = text.Find(L'=');
_items.insert({ n < 0 ? text : text.Left(n), n < 0 ? text : text.Mid(n + 1) });
m_Items.insert({ n < 0 ? text : text.Left(n), n < 0 ? text : text.Mid(n + 1) });
}

return true;
Expand All @@ -85,7 +88,7 @@ bool LocationManager::SaveToFile(PCWSTR path) const {
return false;

IniFile file(path);
for (auto& [name, target] : _items) {
for (auto& [name, target] : m_Items) {
file.WriteString(L"Locations", name, target);
}
return true;
Expand All @@ -94,7 +97,13 @@ bool LocationManager::SaveToFile(PCWSTR path) const {
bool LocationManager::Load(PCWSTR path) {
WCHAR fullpath[MAX_PATH];
::GetModuleFileName(nullptr, fullpath, _countof(fullpath));
wcscpy_s(fullpath + wcslen(fullpath) - 3, _countof(fullpath), L"ini");
auto dot = wcsrchr(fullpath, L'.');
ATLASSERT(dot);
if (!dot)
return false;

*dot = 0;
wcscat_s(fullpath, L".ini");
if (::GetFileAttributes(fullpath) == INVALID_FILE_ATTRIBUTES) {
//
// INIT file does not exist, load from Registry
Expand All @@ -108,49 +117,52 @@ bool LocationManager::Load(PCWSTR path) {
}

bool LocationManager::Save() const {
if (_path.IsEmpty())
if (m_Path.IsEmpty())
return false;

return _path[1] == L':' ? SaveToFile() : SaveToRegistry();
return m_Path[1] == L':' ? SaveToFile() : SaveToRegistry();
}

int LocationManager::GetCount() const {
return (int)_items.size();
return (int)m_Items.size();
}

bool LocationManager::Replace(CString const& name, CString const& newName) {
auto it = _items.find(name);
if (it == _items.end())
auto it = m_Items.find(name);
if (it == m_Items.end())
return false;

auto path = it->second;
_items.erase(it);
_items.insert({ newName, path });
m_Items.erase(it);
m_Items.insert({ newName, path });
return true;
}

void LocationManager::Add(CString const& name, CString const& path) {
_items.insert({ name, path });
m_Items.insert({ name, path });
}

void LocationManager::Clear() {
_items.clear();
m_Items.clear();
}

CString LocationManager::GetPathByName(CString const& name) const {
if (auto it = _items.find(name); it != _items.end())
if (auto it = m_Items.find(name); it != m_Items.end())
return it->second;

if (auto it = _items.find((PCWSTR)name + name.Find(L'/') + 1); it != _items.end())
return it->second;
for (auto& [n, path] : m_Items) {
if (auto index = n.Find(L"/"); index >= 0)
if (n.Mid(index + 1) == name)
return path;
}
return L"";
}

PCWSTR LocationManager::GetPath(PCWSTR path) const {
if (path == nullptr || *path == 0)
path = _path;
path = m_Path;

_path = path;
m_Path = path;
if (path == nullptr || *path == 0)
return nullptr;

Expand Down
8 changes: 4 additions & 4 deletions RegExp/LocationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class LocationManager {
int GetCount() const;

auto begin() {
return _items.begin();
return m_Items.begin();
}

auto end() {
return _items.end();
return m_Items.end();
}

bool Replace(CString const& name, CString const& newName);
Expand All @@ -32,7 +32,7 @@ class LocationManager {
return s1.CompareNoCase(s2) < 0;
}
};
std::map<CString, CString, LessNoCase> _items;
mutable CString _path;
std::map<CString, CString, LessNoCase> m_Items;
mutable CString m_Path;
};

Binary file modified RegExp/RegExp.rc
Binary file not shown.

0 comments on commit af02700

Please sign in to comment.