1 | |
---|
2 | // Copyright Eóin O'Callaghan 2006 - 2008. |
---|
3 | // Distributed under the Boost Software License, Version 1.0. |
---|
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include "global/string_conv.hpp" |
---|
10 | #include "global/wtl_app.hpp" |
---|
11 | |
---|
12 | #include "halIni.hpp" |
---|
13 | |
---|
14 | class BitTorrentOptions; |
---|
15 | class SecurityOptions; |
---|
16 | class ProxyOptions; |
---|
17 | class TorrentsOptions; |
---|
18 | |
---|
19 | namespace hal |
---|
20 | { |
---|
21 | |
---|
22 | class Config : |
---|
23 | public hal::IniBase<Config>, |
---|
24 | private boost::noncopyable |
---|
25 | { |
---|
26 | public: |
---|
27 | Config() : |
---|
28 | hal::IniBase<Config>("globals/bittorrent", "Config"), |
---|
29 | globals_(), |
---|
30 | torrent_defaults_(), |
---|
31 | port_range_(6881,6881), |
---|
32 | use_port_range_(false), |
---|
33 | randomize_port_(false), |
---|
34 | enable_dht_(true), |
---|
35 | dht_settings_(), |
---|
36 | enableIPFilter(false), |
---|
37 | enableProxy(false), |
---|
38 | proxyPort(0), |
---|
39 | default_save_folder_((hal::app().exe_path().parent_path()/L"incoming").string()), |
---|
40 | default_move_folder_((hal::app().exe_path().parent_path()/L"completed").string()), |
---|
41 | use_move_to_(false), |
---|
42 | save_prompt_(true), |
---|
43 | enable_pe_(false), |
---|
44 | pe_settings_(), |
---|
45 | half_connections_(true), |
---|
46 | half_connections_limit_(10), |
---|
47 | mapping_upnp_(false), |
---|
48 | mapping_nat_pmp_(false) |
---|
49 | { |
---|
50 | queue_settings_ = hal::bittorrent().get_queue_settings(); |
---|
51 | timeouts_ = hal::bittorrent().get_timeouts(); |
---|
52 | } |
---|
53 | |
---|
54 | friend class boost::serialization::access; |
---|
55 | template<class Archive> |
---|
56 | void serialize(Archive& ar, const unsigned int version) |
---|
57 | { |
---|
58 | using boost::serialization::make_nvp; |
---|
59 | switch (version) |
---|
60 | { |
---|
61 | case 6: |
---|
62 | ar & make_nvp("globals", globals_) |
---|
63 | & make_nvp("default_save_folder", default_save_folder_) |
---|
64 | & make_nvp("default_move_folder", default_move_folder_) |
---|
65 | & make_nvp("use_move_to", use_move_to_) |
---|
66 | & make_nvp("save_prompt", save_prompt_) |
---|
67 | & make_nvp("randomize_port", randomize_port_) |
---|
68 | & make_nvp("torrent_defaults", torrent_defaults_) |
---|
69 | & make_nvp("queue_settings", queue_settings_) |
---|
70 | & make_nvp("timeouts", timeouts_) |
---|
71 | & make_nvp("enable_dht", enable_dht_) |
---|
72 | & make_nvp("dht_settings", dht_settings_) |
---|
73 | & make_nvp("enable_pe", enable_pe_) |
---|
74 | & make_nvp("pe_settings", pe_settings_) |
---|
75 | & make_nvp("port_range", port_range_) |
---|
76 | & make_nvp("use_port_range", use_port_range_) |
---|
77 | & make_nvp("half_connections", half_connections_) |
---|
78 | & make_nvp("half_connections_limit", half_connections_limit_) |
---|
79 | & make_nvp("mapping_upnp", mapping_upnp_) |
---|
80 | & make_nvp("mapping_nat_pmp", mapping_nat_pmp_); |
---|
81 | break; |
---|
82 | |
---|
83 | case 4: |
---|
84 | ar & make_nvp("defaultMoveToFolder", default_move_folder_) |
---|
85 | & make_nvp("useMoveTo", use_move_to_); |
---|
86 | |
---|
87 | case 3: |
---|
88 | case 2: |
---|
89 | ar & make_nvp("halfConn", half_connections_) |
---|
90 | & make_nvp("halfConnLimit", half_connections_limit_); |
---|
91 | |
---|
92 | case 1: |
---|
93 | ar & make_nvp("enablePe", enable_pe_) |
---|
94 | & make_nvp("peEncLevel", pe_settings_.encrypt_level) |
---|
95 | & make_nvp("pePerferRc4", pe_settings_.prefer_rc4) |
---|
96 | & make_nvp("peConInPolicy", pe_settings_.conn_in_policy) |
---|
97 | & make_nvp("peConOutPolicy", pe_settings_.conn_out_policy); |
---|
98 | |
---|
99 | case 0: |
---|
100 | ar & make_nvp("maxConnections", globals_.total) |
---|
101 | & make_nvp("maxUploads", globals_.uploads) |
---|
102 | & make_nvp("downRate", globals_.download_rate) |
---|
103 | & make_nvp("upRate", globals_.upload_rate) |
---|
104 | & make_nvp("portFrom", port_range_.first) |
---|
105 | & make_nvp("portTo", port_range_.second); |
---|
106 | |
---|
107 | ar & make_nvp("enableDHT", enable_dht_) |
---|
108 | & make_nvp("dhtMaxPeersReply", dht_settings_.max_peers_reply) |
---|
109 | & make_nvp("dhtSearchBranching", dht_settings_.search_branching) |
---|
110 | & make_nvp("dhtServicePort", dht_settings_.service_port) |
---|
111 | & make_nvp("dhtMaxFailCount", dht_settings_.max_fail_count); |
---|
112 | |
---|
113 | ar & make_nvp("peerTimeout", timeouts_.peer_connect_timeout) |
---|
114 | & make_nvp("trackerTimeout", timeouts_.tracker_receive_timeout); |
---|
115 | |
---|
116 | ar & BOOST_SERIALIZATION_NVP(enableIPFilter) |
---|
117 | & make_nvp("portRange", use_port_range_) |
---|
118 | & make_nvp("torrentMaxConnections", torrent_defaults_.total) |
---|
119 | & make_nvp("torrentMaxUploads", torrent_defaults_.uploads) |
---|
120 | & make_nvp("torrentDownRate", torrent_defaults_.download_rate) |
---|
121 | & make_nvp("torrentUpRate", torrent_defaults_.upload_rate) |
---|
122 | & make_nvp("defaultSaveFolder", default_save_folder_) |
---|
123 | & make_nvp("savePrompt", save_prompt_); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | bool settingsChanged(); |
---|
128 | |
---|
129 | friend class HaliteWindow; |
---|
130 | friend class BitTorrentOptions; |
---|
131 | friend class SecurityOptions; |
---|
132 | friend class ProxyOptions; |
---|
133 | friend class TorrentsOptions; |
---|
134 | friend class GlobalOptions; |
---|
135 | friend class PortOptions; |
---|
136 | |
---|
137 | private: |
---|
138 | bool settingsThread(); |
---|
139 | |
---|
140 | hal::connections globals_; |
---|
141 | |
---|
142 | std::pair<int, int> port_range_; |
---|
143 | bool use_port_range_; |
---|
144 | bool randomize_port_; |
---|
145 | |
---|
146 | hal::connections torrent_defaults_; |
---|
147 | |
---|
148 | std::wstring default_save_folder_; |
---|
149 | std::wstring default_move_folder_; |
---|
150 | bool use_move_to_; |
---|
151 | bool save_prompt_; |
---|
152 | |
---|
153 | bool enable_dht_; |
---|
154 | hal::dht_settings dht_settings_; |
---|
155 | |
---|
156 | bool enableIPFilter; |
---|
157 | |
---|
158 | bool enableProxy; |
---|
159 | std::wstring proxyHost; |
---|
160 | int proxyPort; |
---|
161 | std::wstring proxyUsername; |
---|
162 | std::wstring proxyPassword; |
---|
163 | |
---|
164 | |
---|
165 | bool enable_pe_; |
---|
166 | hal::pe_settings pe_settings_; |
---|
167 | |
---|
168 | bool half_connections_; |
---|
169 | int half_connections_limit_; |
---|
170 | |
---|
171 | bool mapping_upnp_; |
---|
172 | bool mapping_nat_pmp_; |
---|
173 | |
---|
174 | hal::queue_settings queue_settings_; |
---|
175 | hal::timeouts timeouts_; |
---|
176 | }; |
---|
177 | |
---|
178 | Config& config(); |
---|
179 | |
---|
180 | } // namespace hal |
---|
181 | |
---|
182 | BOOST_CLASS_VERSION(hal::Config, 6) |
---|