Skip to content

Commit

Permalink
修正某些情况下修改文件关联失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Oct 10, 2013
1 parent eda5f3c commit 6ee4a41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 27 additions & 6 deletions Development/Editor/Core/YDWEConfig/Regedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,46 @@ bool FileAssociation::Ext::set(winstl::reg_key_w const& root, Classes const& c)
return false;
}

bool FileAssociation::Ext::has_owl(winstl::reg_key_w& root) const
{
try {
return root.open_sub_key(ext_.c_str()).has_value(L"Application");
} catch (winstl::registry_exception const& ) { }

return false;
}

bool FileAssociation::Ext::set_owl(winstl::reg_key_w& root)
{
try {
return root.open_sub_key(ext_.c_str()).delete_value(L"Application");
} catch (winstl::registry_exception const& ) { }

return false;
}

FileAssociation::FileAssociation(fs::path const& ydwe_path)
: root_(HKEY_CURRENT_USER, L"Software\\Classes")
, root2_(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts")
, classes_(L"YDWEMap")
, ext_w3x_(L".w3x")
, ext_w3m_(L".w3m")
, icon_path_(ydwe_path.parent_path() / L"bin" / L"logo.ico")
, command_(L"\"" + ydwe_path.wstring() + L"\" -loadfile \"%1\"")
{
}
{ }

bool FileAssociation::has_w3x()
{
return classes_.has(root_, command_) && ext_w3x_.has(root_, classes_);
return classes_.has(root_, command_)
&& ext_w3x_.has(root_, classes_)
&& ext_w3x_.has_owl(root2_);
}

bool FileAssociation::has_w3m()
{
return classes_.has(root_, command_) && ext_w3m_.has(root_, classes_);
return classes_.has(root_, command_)
&& ext_w3m_.has(root_, classes_)
&& ext_w3m_.has_owl(root2_);
}

bool FileAssociation::remove_w3x()
Expand All @@ -175,12 +196,12 @@ void FileAssociation::remove()

bool FileAssociation::set_w3x()
{
return ext_w3x_.set(root_, classes_);
return ext_w3x_.set(root_, classes_) && ext_w3x_.set_owl(root2_);
}

bool FileAssociation::set_w3m()
{
return ext_w3m_.set(root_, classes_);
return ext_w3m_.set(root_, classes_) && ext_w3m_.set_owl(root2_);
}

bool FileAssociation::set_classes()
Expand Down
4 changes: 4 additions & 0 deletions Development/Editor/Core/YDWEConfig/Regedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class FileAssociation
bool remove(winstl::reg_key_w const& root);
bool set(winstl::reg_key_w const& root, Classes const& c);

bool has_owl(winstl::reg_key_w& root) const;
bool set_owl(winstl::reg_key_w& root);

private:
std::wstring ext_;
};
Expand All @@ -57,6 +60,7 @@ class FileAssociation
bool remove_classes();

winstl::reg_key_w root_;
winstl::reg_key_w root2_;
FileAssociation::Classes classes_;
FileAssociation::Ext ext_w3x_;
FileAssociation::Ext ext_w3m_;
Expand Down

0 comments on commit 6ee4a41

Please sign in to comment.