|
1
|
1 #pragma once
|
|
|
2
|
|
|
3 //! Entrypoint interface for declaring component's version information. Instead of implementing this directly, use DECLARE_COMPONENT_VERSION().
|
|
|
4 class NOVTABLE componentversion : public service_base {
|
|
|
5 public:
|
|
|
6 virtual void get_file_name(pfc::string_base & out)=0;
|
|
|
7 virtual void get_component_name(pfc::string_base & out)=0;
|
|
|
8 virtual void get_component_version(pfc::string_base & out)=0;
|
|
|
9 virtual void get_about_message(pfc::string_base & out)=0;//about message uses "\n" for line separators
|
|
|
10
|
|
|
11 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(componentversion);
|
|
|
12 };
|
|
|
13
|
|
|
14 //! Implementation helper. You typically want to use DECLARE_COMPONENT_VERSION() instead.
|
|
|
15 class componentversion_impl_simple : public componentversion {
|
|
|
16 const char * name,*version,*about;
|
|
|
17 public:
|
|
|
18 //do not derive/override
|
|
|
19 virtual void get_file_name(pfc::string_base & out) {out.set_string(core_api::get_my_file_name());}
|
|
|
20 virtual void get_component_name(pfc::string_base & out) {out.set_string(name?name:"");}
|
|
|
21 virtual void get_component_version(pfc::string_base & out) {out.set_string(version?version:"");}
|
|
|
22 virtual void get_about_message(pfc::string_base & out) {out.set_string(about?about:"");}
|
|
|
23 explicit componentversion_impl_simple(const char * p_name,const char * p_version,const char * p_about) : name(p_name), version(p_version), about(p_about ? p_about : "") {}
|
|
|
24 };
|
|
|
25
|
|
|
26 //! Implementation helper. You typically want to use DECLARE_COMPONENT_VERSION() instead.
|
|
|
27 class componentversion_impl_copy : public componentversion {
|
|
|
28 pfc::string8 name,version,about;
|
|
|
29 public:
|
|
|
30 //do not derive/override
|
|
|
31 virtual void get_file_name(pfc::string_base & out) {out.set_string(core_api::get_my_file_name());}
|
|
|
32 virtual void get_component_name(pfc::string_base & out) {out.set_string(name);}
|
|
|
33 virtual void get_component_version(pfc::string_base & out) {out.set_string(version);}
|
|
|
34 virtual void get_about_message(pfc::string_base & out) {out.set_string(about);}
|
|
|
35 explicit componentversion_impl_copy(const char * p_name,const char * p_version,const char * p_about) : name(p_name), version(p_version), about(p_about ? p_about : "") {}
|
|
|
36 };
|
|
|
37
|
|
|
38 typedef service_factory_single_transparent_t<componentversion_impl_simple> __componentversion_impl_simple_factory;
|
|
|
39 typedef service_factory_single_transparent_t<componentversion_impl_copy> __componentversion_impl_copy_factory;
|
|
|
40
|
|
|
41 class componentversion_impl_simple_factory : public __componentversion_impl_simple_factory {
|
|
|
42 public:
|
|
|
43 componentversion_impl_simple_factory(const char * p_name,const char * p_version,const char * p_about) : __componentversion_impl_simple_factory(p_name,p_version,p_about) {}
|
|
|
44 };
|
|
|
45
|
|
|
46 class componentversion_impl_copy_factory : public __componentversion_impl_copy_factory {
|
|
|
47 public:
|
|
|
48 componentversion_impl_copy_factory(const char * p_name,const char * p_version,const char * p_about) : __componentversion_impl_copy_factory(p_name,p_version,p_about) {}
|
|
|
49 };
|
|
|
50
|
|
|
51 //! Use this to declare your component's version information. Parameters must ba plain const char * string constants. \n
|
|
|
52 //! You should have only one DECLARE_COMPONENT_VERSION() per component DLL. Having more than one will confuse component updater's version matching. \n
|
|
|
53 //! Please keep your version numbers formatted as: N[.N[.N....]][ alpha|beta|RC[ N[.N...]] \n
|
|
|
54 //! Sample version numbers, in ascending order: 0.9 < 0.10 < 1.0 alpha 1 < 1.0 alpha 2 < 1.0 beta 1 < 1.0 RC < 1.0 RC1 < 1.0 < 1.1 < 1.10 \n
|
|
|
55 //! For a working sample of how foobar2000 sorts version numbers, see http://www.foobar2000.org/versionator.php \n
|
|
|
56 //! Example: DECLARE_COMPONENT_VERSION("blah","1.3.3.7","")
|
|
|
57 #define DECLARE_COMPONENT_VERSION(NAME,VERSION,ABOUT) \
|
|
|
58 namespace {class componentversion_myimpl : public componentversion { public: componentversion_myimpl() {PFC_ASSERT( ABOUT );} \
|
|
|
59 void get_file_name(pfc::string_base & out) {out = core_api::get_my_file_name();} \
|
|
|
60 void get_component_name(pfc::string_base & out) {out = NAME;} \
|
|
|
61 void get_component_version(pfc::string_base & out) {out = VERSION;} \
|
|
|
62 void get_about_message(pfc::string_base & out) {out = ABOUT;} \
|
|
|
63 }; static service_factory_single_t<componentversion_myimpl> g_componentversion_myimpl_factory; }
|
|
|
64 // static componentversion_impl_simple_factory g_componentversion_service(NAME,VERSION,ABOUT);
|
|
|
65
|
|
|
66 //! Same as DECLARE_COMPONENT_VERSION(), but parameters can be dynamically generated strings rather than compile-time constants.
|
|
|
67 #define DECLARE_COMPONENT_VERSION_COPY(NAME,VERSION,ABOUT) \
|
|
|
68 static componentversion_impl_copy_factory g_componentversion_service(NAME,VERSION,ABOUT);
|
|
|
69
|
|
|
70
|
|
|
71 //! \since 1.0
|
|
|
72 //! Allows components to cleanly abort app startup in case the installation appears to have become corrupted.
|
|
|
73 class component_installation_validator : public service_base {
|
|
|
74 public:
|
|
|
75 virtual bool is_installed_correctly() = 0;
|
|
|
76
|
|
|
77 static bool test_my_name(const char * fn);
|
|
|
78 static bool have_other_file(const char * fn);
|
|
|
79
|
|
|
80 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(component_installation_validator)
|
|
|
81 };
|
|
|
82
|
|
|
83 #ifdef _WIN32
|
|
|
84 //! Simple implementation of component_installation_validator that makes sure that our component DLL has not been renamed around by idiot users.
|
|
|
85 class component_installation_validator_filename : public component_installation_validator {
|
|
|
86 public:
|
|
|
87 component_installation_validator_filename(const char * dllName) : m_dllName(dllName) {}
|
|
|
88 bool is_installed_correctly() {
|
|
|
89 return test_my_name(m_dllName);
|
|
|
90 }
|
|
|
91 private:
|
|
|
92 const char * const m_dllName;
|
|
|
93 };
|
|
|
94
|
|
|
95 #define VALIDATE_COMPONENT_FILENAME(FN) \
|
|
|
96 static service_factory_single_t<component_installation_validator_filename> g_component_installation_validator_filename(FN);
|
|
|
97
|
|
|
98 #else // _WIN32
|
|
|
99
|
|
|
100 #define VALIDATE_COMPONENT_FILENAME(FN)
|
|
|
101
|
|
|
102 #endif // _WIN32
|
|
|
103
|