1
////////////////////////////////////////////////////////////////////////////
2
// NoteCase notes manager project <http://notecase.sf.net>
4
// This code is licensed under BSD license.See "license.txt" for more details.
6
// File: Class to register document format (*.ext) to be handled by given application
7
////////////////////////////////////////////////////////////////////////////
9
#include "RegisterExtension.h"
12
RegisterFileExtension::RegisterFileExtension()
17
RegisterFileExtension::~RegisterFileExtension()
21
void RegisterFileExtension::ClearData()
31
void RegisterFileExtension::AddShellAction(const char *szName, const char *szCmd)
33
//encode both string into one
34
std::string strData(szName);
39
m_lstCmds.push_back(strData);
42
void RegisterFileExtension::UpdateRegistry()
44
Key_CreateRoot(m_strExt.c_str(), "", m_strName.c_str()); //write ext key
45
Key_CreateRoot(m_strName.c_str(), "", m_strDesc.c_str()); //write description key
47
if(m_nIconIndex != -1)
49
std::string strKey(m_strName);
50
strKey += "\\DefaultIcon";
53
std::string strVal(m_strIconApp);
55
strVal += itoa(m_nIconIndex, buffer, 10);
57
Key_CreateRoot(strKey.c_str(), "", strVal.c_str()); //write default icon
60
for(int i=0; i<m_lstCmds.size(); i++)
62
int nDivider = m_lstCmds[i].find("\t");
64
std::string strKey(m_strName);
65
strKey += "\\Shell\\";
66
strKey += m_lstCmds[i].substr(0, nDivider);
68
//TOFIX action can have a description
69
Key_CreateRoot(strKey.c_str(), "", ""); //write action name
71
strKey += "\\command";
72
Key_CreateRoot(strKey.c_str(), "", m_lstCmds[i].substr(nDivider+1,2000).c_str()); //write action command subkey
75
//sett default shell action - wrtie action name under "/Shell/"
76
if(!m_strDefaultCmd.empty())
78
std::string strKey(m_strName);
79
strKey += "\\Shell\\";
81
Key_CreateRoot(strKey.c_str(), "", m_strDefaultCmd.c_str()); //write action name
85
//create registry key, and write name/value pair (of string type) into it
86
//registry path starts at root (hardcoded limit), and can be up to 4 levels deep (RegCreateKey limitation)
87
bool RegisterFileExtension::Key_CreateRoot(const char *szPath, const char *szName, const char *szValue)
89
HKEY hBase = HKEY_CLASSES_ROOT; // handle to the parent key
90
HKEY hKey; // handle to the open registry key
92
LONG lRes = RegCreateKey(hBase, szPath, &hKey);
93
if(lRes == ERROR_SUCCESS)
96
if( NULL != szValue &&
99
RegSetValue(hKey, szName, REG_SZ, szValue, strlen(szValue));
109
bool RegisterFileExtension::IsRegistered(const char *szExt)
111
HKEY hKey; // handle to the open registry key
112
if(ERROR_SUCCESS == RegOpenKey(HKEY_CLASSES_ROOT, szExt, &hKey))