Clone
ixen <ixen@copyhandler.com>
committed
on 07 Sep 10
Got rid of unused error code/message field in status dialog.
LoggerImprovements + 5 more
src/ch/AppHelper.cpp (+8 -63)
95 95                         return false;
96 96         }
97 97
98 98         // create directory for tasks
99 99         if(!CreateDirectory(rStrPath + _T("\\Tasks"), nullptr) && GetLastError() != ERROR_ALREADY_EXISTS)
100 100                 return false;
101 101
102 102         return true;
103 103 }
104 104
105 105 CString CAppHelper::ExpandPath(CString strPath)
106 106 {
107 107         return m_pathProcessor.ExpandPath(strPath);
108 108 }
109 109
110 110 CString CAppHelper::GetProgramPath() const
111 111 {
112 112         return m_pathProcessor.GetProgramPath();
113 113 }
114 114
  115 CString CAppHelper::GetFullProgramPath() const
  116 {
  117         CString strKey;
  118         strKey.Format(_T("%s\\%s"), (PCTSTR)m_pathProcessor.GetProgramPath(), m_pszProgramName);
  119
  120         return strKey;
  121 }
  122
115 123 bool CAppHelper::IsInPortableMode()
116 124 {
117 125         if(!m_optPortableMode.is_initialized())
118 126         {
119 127                 // check if the ch.ini exists in the program's directory - it is the only way we can determine portable mode
120 128                 CString strPortableCfgPath = CString(m_pathProcessor.GetProgramPath()) + _T("\\ch.xml");
121 129                 if(GetFileAttributes(strPortableCfgPath) == INVALID_FILE_ATTRIBUTES)
122 130                         m_optPortableMode = false;
123 131                 else
124 132                         m_optPortableMode = true;
125 133         }
126 134
127 135         return m_optPortableMode.get();
128 136 }
129  
130   bool CAppHelper::SetAutorun(bool bEnable)
131   {
132           // check the current key value (to avoid irritating messages from some firewall software)
133           HKEY hkeyRun = nullptr;
134           CString strValue;
135           CString strKey;
136           DWORD dwType = REG_SZ;
137           DWORD dwCount = _MAX_PATH * sizeof(TCHAR);
138  
139           LSTATUS lStatus = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_QUERY_VALUE, &hkeyRun);
140           if(lStatus != ERROR_SUCCESS)
141                   return false;
142  
143           lStatus = RegQueryValueEx(hkeyRun, m_pszAppName, nullptr, &dwType, (BYTE*)strValue.GetBufferSetLength(_MAX_PATH), &dwCount);
144           RegCloseKey(hkeyRun);
145  
146           if(lStatus != ERROR_SUCCESS && lStatus != ERROR_FILE_NOT_FOUND)
147           {
148                   strValue.ReleaseBuffer(0);
149                   return false;
150           }
151           if(lStatus == ERROR_FILE_NOT_FOUND)
152           {
153                   strValue.ReleaseBuffer(0);
154  
155                   // if there is no key in registry and we don't want it, then return with ok status
156                   if(!bEnable)
157                           return true;
158  
159                   // format the data to be written to registry
160                   strKey.Format(_T("%s\\%s"), (PCTSTR)m_pathProcessor.GetProgramPath(), m_pszProgramName);
161           }
162           else
163           {
164                   // key found
165                   strValue.ReleaseBuffer(dwCount / sizeof(TCHAR));
166  
167                   if(bEnable)
168                   {
169                           // key exists in registry, check if the value is correct
170                           strKey.Format(_T("%s\\%s"), (PCTSTR)m_pathProcessor.GetProgramPath(), m_pszProgramName);
171  
172                           if(strValue.CompareNoCase(strKey) == 0)
173                                   return true;
174                   }
175           }
176  
177           // we want to write information to the registry
178           // storing key in registry
179           lStatus = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hkeyRun);
180           if(lStatus != ERROR_SUCCESS)
181                   return false;
182           
183           if(bEnable)
184                   lStatus = RegSetValueEx(hkeyRun, m_pszAppName, 0, REG_SZ, (BYTE*)(PCTSTR)strKey, (DWORD)(strKey.GetLength() + 1) * sizeof(TCHAR));
185           else
186                   lStatus = RegDeleteValue(hkeyRun, m_pszAppName);
187           
188           RegCloseKey(hkeyRun);
189  
190           return lStatus == ERROR_SUCCESS;
191   }