OLD | NEW |
| (Empty) |
1 // Copyright 2007-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // Omaha resource manager. | |
17 | |
18 #ifndef OMAHA_GOOPDATE_RESOURCE_MANAGER_H__ | |
19 #define OMAHA_GOOPDATE_RESOURCE_MANAGER_H__ | |
20 | |
21 #include <atlstr.h> | |
22 #include <map> | |
23 #include <vector> | |
24 #include "base/basictypes.h" | |
25 #include "base/synchronized.h" | |
26 | |
27 namespace omaha { | |
28 | |
29 class ResourceManager { | |
30 public: | |
31 // Create must be called before going multithreaded. | |
32 static HRESULT CreateForDefaultLanguage(bool is_machine, | |
33 const CString& resource_dir); | |
34 static HRESULT Create(bool is_machine, | |
35 const CString& resource_dir, | |
36 const CString& lang); | |
37 static void Delete(); | |
38 | |
39 static ResourceManager& Instance(); | |
40 | |
41 static void GetSupportedLanguageDllNames(std::vector<CString>* filenames); | |
42 | |
43 // Gets resource DLL handle for the given language. DLL will be loaded if | |
44 // necessary. | |
45 HRESULT GetResourceDll(const CString& language, HINSTANCE* dll_handle); | |
46 | |
47 private: | |
48 struct ResourceDllInfo { | |
49 ResourceDllInfo() : dll_handle(NULL) {} | |
50 | |
51 HMODULE dll_handle; | |
52 CString file_path; | |
53 CString language; | |
54 }; | |
55 | |
56 ResourceManager(bool is_machine, const CString& resource_dir); | |
57 ~ResourceManager(); | |
58 | |
59 // The resource manager tries to load the resource dll corresponding to | |
60 // the language in the following order: | |
61 // 1. Language parameter. | |
62 // 2. Language in the registry. | |
63 // 3. First file returned by NTFS in the module directory. | |
64 HRESULT LoadResourceDll(const CString& language, ResourceDllInfo* dll_info); | |
65 HRESULT SetDefaultResourceByLanguage(const CString& language); | |
66 HRESULT LoadLibraryAsDataFile(const CString& filename, | |
67 ResourceDllInfo* dll_info) const; | |
68 | |
69 // Gets resource DLL info for the given language. DLL will be loaded if | |
70 // necessary. | |
71 HRESULT GetResourceDllInfo(const CString& language, | |
72 ResourceDllInfo* dll_info); | |
73 | |
74 static CString GetResourceDllName(const CString& language); | |
75 | |
76 LLock lock_; | |
77 typedef std::map<CString, ResourceDllInfo> LanguageToResourceMap; | |
78 | |
79 bool is_machine_; | |
80 CString resource_dir_; | |
81 LanguageToResourceMap resource_map_; | |
82 HINSTANCE saved_atl_resource_; | |
83 | |
84 static ResourceManager* instance_; | |
85 | |
86 friend class ResourceManagerTest; | |
87 | |
88 DISALLOW_EVIL_CONSTRUCTORS(ResourceManager); | |
89 }; | |
90 | |
91 } // namespace omaha | |
92 | |
93 #endif // OMAHA_GOOPDATE_RESOURCE_MANAGER_H__ | |
OLD | NEW |