Skip to content

Commit 6ee4a41

Browse files
committed
修正某些情况下修改文件关联失效的问题
1 parent eda5f3c commit 6ee4a41

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Development/Editor/Core/YDWEConfig/Regedit.cpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,46 @@ bool FileAssociation::Ext::set(winstl::reg_key_w const& root, Classes const& c)
130130
return false;
131131
}
132132

133+
bool FileAssociation::Ext::has_owl(winstl::reg_key_w& root) const
134+
{
135+
try {
136+
return root.open_sub_key(ext_.c_str()).has_value(L"Application");
137+
} catch (winstl::registry_exception const& ) { }
138+
139+
return false;
140+
}
141+
142+
bool FileAssociation::Ext::set_owl(winstl::reg_key_w& root)
143+
{
144+
try {
145+
return root.open_sub_key(ext_.c_str()).delete_value(L"Application");
146+
} catch (winstl::registry_exception const& ) { }
147+
148+
return false;
149+
}
133150

134151
FileAssociation::FileAssociation(fs::path const& ydwe_path)
135152
: root_(HKEY_CURRENT_USER, L"Software\\Classes")
153+
, root2_(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts")
136154
, classes_(L"YDWEMap")
137155
, ext_w3x_(L".w3x")
138156
, ext_w3m_(L".w3m")
139157
, icon_path_(ydwe_path.parent_path() / L"bin" / L"logo.ico")
140158
, command_(L"\"" + ydwe_path.wstring() + L"\" -loadfile \"%1\"")
141-
{
142-
}
159+
{ }
143160

144161
bool FileAssociation::has_w3x()
145162
{
146-
return classes_.has(root_, command_) && ext_w3x_.has(root_, classes_);
163+
return classes_.has(root_, command_)
164+
&& ext_w3x_.has(root_, classes_)
165+
&& ext_w3x_.has_owl(root2_);
147166
}
148167

149168
bool FileAssociation::has_w3m()
150169
{
151-
return classes_.has(root_, command_) && ext_w3m_.has(root_, classes_);
170+
return classes_.has(root_, command_)
171+
&& ext_w3m_.has(root_, classes_)
172+
&& ext_w3m_.has_owl(root2_);
152173
}
153174

154175
bool FileAssociation::remove_w3x()
@@ -175,12 +196,12 @@ void FileAssociation::remove()
175196

176197
bool FileAssociation::set_w3x()
177198
{
178-
return ext_w3x_.set(root_, classes_);
199+
return ext_w3x_.set(root_, classes_) && ext_w3x_.set_owl(root2_);
179200
}
180201

181202
bool FileAssociation::set_w3m()
182203
{
183-
return ext_w3m_.set(root_, classes_);
204+
return ext_w3m_.set(root_, classes_) && ext_w3m_.set_owl(root2_);
184205
}
185206

186207
bool FileAssociation::set_classes()

Development/Editor/Core/YDWEConfig/Regedit.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class FileAssociation
3838
bool remove(winstl::reg_key_w const& root);
3939
bool set(winstl::reg_key_w const& root, Classes const& c);
4040

41+
bool has_owl(winstl::reg_key_w& root) const;
42+
bool set_owl(winstl::reg_key_w& root);
43+
4144
private:
4245
std::wstring ext_;
4346
};
@@ -57,6 +60,7 @@ class FileAssociation
5760
bool remove_classes();
5861

5962
winstl::reg_key_w root_;
63+
winstl::reg_key_w root2_;
6064
FileAssociation::Classes classes_;
6165
FileAssociation::Ext ext_w3x_;
6266
FileAssociation::Ext ext_w3m_;

0 commit comments

Comments
 (0)