Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

Settings.cpp

Go to the documentation of this file.
00001 //
00002 // Settings.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Schema.h"
00026 #include "Skin.h"
00027 #include "Registry.h"
00028 
00029 #ifdef _DEBUG
00030 #undef THIS_FILE
00031 static char THIS_FILE[]=__FILE__;
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 CSettings Settings;
00036 
00037 
00039 // CSettings setup
00040 
00041 void CSettings::Setup()
00042 {
00043         Add( _T(".Path"), &General.Path, General.Path );
00044         Add( _T(".UserPath"), &General.UserPath, General.UserPath );
00045         Add( _T(".Debug"), &General.Debug, FALSE );
00046         Add( _T(".DebugLog"), &General.DebugLog, FALSE );
00047         Add( _T(".MaxDebugLogSize"), &General.MaxDebugLogSize, 10*1024*1024 );
00048         Add( _T(".UpdateCheck"), &General.UpdateCheck, TRUE );
00049         Add( _T(".HashIntegrity"), &General.HashIntegrity, TRUE );
00050         Add( _T(".DiskSpaceWarning"), &General.DiskSpaceWarning, 500 );
00051         Add( _T(".DiskSpaceStop"), &General.DiskSpaceStop, 25 );
00052         Add( _T(".MinTransfersRest"), &General.MinTransfersRest, 15 );
00053         Add( _T("Settings.GUIMode"), &General.GUIMode, GUI_BASIC );
00054         Add( _T("Settings.CloseMode"), &General.CloseMode, 0 );
00055         Add( _T("Settings.TrayMinimise"), &General.TrayMinimise, FALSE );
00056         Add( _T("Settings.VerboseMode"), &General.VerboseMode, TRUE );
00057         Add( _T("Settings.ShowTimestamp"), &General.ShowTimestamp, TRUE );
00058         Add( _T("Settings.SizeLists"), &General.SizeLists, FALSE );
00059         Add( _T("Settings.RatesInBytes"), &General.RatesInBytes, FALSE );
00060         Add( _T("Settings.RatesUnit"), &General.RatesUnit, 0 );
00061         Add( _T("Settings.AlwaysOpenURLs"), &General.AlwaysOpenURLs, FALSE );
00062         Add( _T("Settings.Language"), &General.Language, _T("en") );
00063         Add( _T("Settings.IgnoreXPsp2"), &General.IgnoreXPsp2, FALSE );
00064         
00065         Add( _T("Interface.TipDelay"), &Interface.TipDelay, 600 );
00066         Add( _T("Interface.TipAlpha"), &Interface.TipAlpha, 230 );
00067         Add( _T("Interface.TipSearch"), &Interface.TipSearch, TRUE );
00068         Add( _T("Interface.TipLibrary"), &Interface.TipLibrary, TRUE );
00069         Add( _T("Interface.TipDownloads"), &Interface.TipDownloads, TRUE );
00070         Add( _T("Interface.TipUploads"), &Interface.TipUploads, TRUE );
00071         Add( _T("Interface.TipNeighbours"), &Interface.TipNeighbours, TRUE );
00072         Add( _T("Interface.TipMedia"), &Interface.TipMedia, TRUE );
00073         Add( _T("Interface.LowResMode"), &Interface.LowResMode, FALSE );
00074         
00075         Add( _T("Library.WatchFolders"), &Library.WatchFolders, TRUE );
00076         Add( _T("Library.PartialMatch"), &Library.PartialMatch, TRUE );
00077         Add( _T("Library.VirtualFiles"), &Library.VirtualFiles, TRUE );
00078         Add( _T("Library.SourceMesh"), &Library.SourceMesh, TRUE );
00079         Add( _T("Library.SourceExpire"), &Library.SourceExpire, 86400 );
00080         Add( _T("Library.TigerHeight"), &Library.TigerHeight, 9 );
00081         Add( _T("Library.QueryRouteSize"), &Library.QueryRouteSize, 20 );
00082         Add( _T("Library.HistoryTotal"), &Library.HistoryTotal, 32 );
00083         Add( _T("Library.HistoryDays"), &Library.HistoryDays, 3 );
00084         Add( _T("Library.ShowVirtual"), &Library.ShowVirtual, TRUE );
00085         Add( _T("Library.TreeSize"), &Library.TreeSize, 200 );
00086         Add( _T("Library.PanelSize"), &Library.PanelSize, 120 );
00087         Add( _T("Library.ShowPanel"), &Library.ShowPanel, TRUE );
00088         Add( _T("Library.StoreViews"), &Library.StoreViews, TRUE );
00089         Add( _T("Library.ShowCoverArt"), &Library.ShowCoverArt, TRUE );
00090         Add( _T("Library.SchemaURI"), &Library.SchemaURI, CSchema::uriAudio );
00091         Add( _T("Library.FilterURI"), &Library.FilterURI, NULL );
00092         Add( _T("Library.SafeExecute"), &Library.SafeExecute, _T("|ace|ape|asf|avi|bmp|gif|iso|jpg|jpeg|mid|mov|m1v|m2v|m3u|mp2|mp3|mpa|mpe|mpg|mpeg|ogg|pdf|png|qt|rar|rm|sks|tar|tgz|torrent|txt|wav|wma|wmv|zip|") );
00093         Add( _T("Library.PrivateTypes"), &Library.PrivateTypes, _T("|vbs|js|dat|part|partial|getright|pif|lnk|sd|url|") );
00094         Add( _T("Library.ThumbSize"), &Library.ThumbSize, 96 );
00095         Add( _T("Library.BitziWebView"), &Library.BitziWebView, _T("http://bitzi.com/lookup/(SHA1)?detail&ref=shareaza") );
00096         Add( _T("Library.BitziWebSubmit"), &Library.BitziWebSubmit, _T("http://bitzi.com/lookup/(SHA1).(TTH)?fl=(SIZE)&ff=(FIRST20)&fn=(NAME)&a=(AGENT)&v=Q0.4&ref=shareaza") );
00097         Add( _T("Library.BitziXML"), &Library.BitziXML, _T("http://ticket.bitzi.com/rdf/(SHA1)") );
00098         Add( _T("Library.BitziOkay"), &Library.BitziOkay, FALSE );
00099         Add( _T("Library.HighPriorityHash"), &Library.HighPriorityHash, FALSE );
00100         Add( _T("Library.HashWindow"), &Library.HashWindow, FALSE );
00101 
00102         Add( _T("Library.BufferSize"), &Library.BufferSize, 0 );
00103         Add( _T("Library.Parallel"), &Library.Parallel, 0 );
00104         Add( _T("Library.LowPriorityHashing"), &Library.LowPriorityHashing, 5 );
00105         
00106         Add( _T("Search.LastSchemaURI"), &Search.LastSchemaURI, _T("") );
00107         Add( _T("Search.BlankSchemaURI"), &Search.BlankSchemaURI, CSchema::uriAudio );
00108         Add( _T("Search.HideSearchPanel"), &Search.HideSearchPanel, FALSE );
00109         Add( _T("Search.SearchPanel"), &Search.SearchPanel, TRUE );
00110         Add( _T("Search.ExpandMatches"), &Search.ExpandMatches, FALSE );
00111         Add( _T("Search.HighlightNew"), &Search.HighlightNew, TRUE );
00112         Add( _T("Search.SwitchToTransfers"), &Search.SwitchToTransfers, TRUE );
00113         Add( _T("Search.SchemaTypes"), &Search.SchemaTypes, TRUE );
00114         Add( _T("Search.ShowNames"), &Search.ShowNames, TRUE );
00115         Add( _T("Search.FilterMask"), &Search.FilterMask, 0x28 );
00116         Add( _T("Search.MonitorSchemaURI"), &Search.MonitorSchemaURI, CSchema::uriAudio );
00117         Add( _T("Search.MonitorFilter"), &Search.MonitorFilter, NULL );
00118         Add( _T("Search.MonitorQueue"), &Search.MonitorQueue, 128 );
00119         Add( _T("Search.BrowseTreeSize"), &Search.BrowseTreeSize, 180 );
00120         Add( _T("Search.DetailPanelVisible"), &Search.DetailPanelVisible, TRUE );
00121         Add( _T("Search.DetailPanelSize"), &Search.DetailPanelSize, 100 );
00122         Add( _T("Search.MaxPreviewLength"), &Search.MaxPreviewLength, 20*1024 );
00123         Add( _T("Search.AdultFilter"), &Search.AdultFilter, FALSE );
00124         Add( _T("Search.AdvancedPanel"), &Search.AdvancedPanel, TRUE );
00125         Add( _T("Search.GeneralThrottle"), &Search.GeneralThrottle, 200 );
00126 
00127         Add( _T("MediaPlayer.EnablePlay"), &MediaPlayer.EnablePlay, TRUE );
00128         Add( _T("MediaPlayer.EnableEnqueue"), &MediaPlayer.EnableEnqueue, TRUE );
00129         Add( _T("MediaPlayer.FileTypes"), &MediaPlayer.FileTypes, _T("|asx|wax|m3u|wvx|wmx|asf|wav|snd|au|aif|aifc|aiff|wma|mp3|cda|mid|rmi|midi|avi|mpeg|mpg|m1v|mp2|mpa|mpe|wmv|") );
00130         Add( _T("MediaPlayer.Repeat"), &MediaPlayer.Repeat, FALSE );
00131         Add( _T("MediaPlayer.Random"), &MediaPlayer.Random, FALSE );
00132         Add( _T("MediaPlayer.Zoom"), (DWORD*)&MediaPlayer.Zoom, smzFill );
00133         Add( _T("MediaPlayer.Aspect"), &MediaPlayer.Aspect, smaDefault );
00134         Add( _T("MediaPlayer.Volume"), &MediaPlayer.Volume, 1.0f );
00135         Add( _T("MediaPlayer.ListVisible"), &MediaPlayer.ListVisible, TRUE );
00136         Add( _T("MediaPlayer.ListSize"), &MediaPlayer.ListSize, 240 );
00137         Add( _T("MediaPlayer.StatusVisible"), &MediaPlayer.StatusVisible, TRUE );
00138         Add( _T("MediaPlayer.VisCLSID"), &MediaPlayer.VisCLSID, _T("{591A5CFF-3172-4020-A067-238542DDE9C2}") );
00139         Add( _T("MediaPlayer.VisPath"), &MediaPlayer.VisPath, _T("") );
00140         Add( _T("MediaPlayer.VisSize"), &MediaPlayer.VisSize, 1 );
00141         
00142         Add( _T("Web.Magnet"), &Web.Magnet, TRUE );
00143         Add( _T("Web.Gnutella"), &Web.Gnutella, TRUE );
00144         Add( _T("Web.ED2K"), &Web.ED2K, TRUE );
00145         Add( _T("Web.Piolet"), &Web.Piolet, TRUE );
00146         Add( _T("Web.Torrent"), &Web.Torrent, TRUE );
00147         
00148         Add( _T("Connection.AutoConnect"), &Connection.AutoConnect, FALSE );
00149         Add( _T("Connection.FirewallStatus"), &Connection.FirewallStatus, CONNECTION_AUTO );
00150         Add( _T("Connection.OutHost"), &Connection.OutHost, NULL );
00151         Add( _T("Connection.InHost"), &Connection.InHost, NULL );
00152         Add( _T("Connection.InPort"), &Connection.InPort, GNUTELLA_DEFAULT_PORT );
00153         Add( _T("Connection.InBind"), &Connection.InBind, FALSE );
00154         Add( _T("Connection.InSpeed"), &Connection.InSpeed, 56 );
00155         Add( _T("Connection.OutSpeed"), &Connection.OutSpeed, 56 );
00156         Add( _T("Connection.IgnoreLocalIP"), &Connection.IgnoreLocalIP, TRUE );
00157         Add( _T("Connection.IgnoreOwnIP"), &Connection.IgnoreOwnIP, TRUE );
00158         Add( _T("Connection.TimeoutConnect"), &Connection.TimeoutConnect, 16000 );
00159         Add( _T("Connection.TimeoutHandshake"), &Connection.TimeoutHandshake, 45000 );
00160         Add( _T("Connection.TimeoutTraffic"), &Connection.TimeoutTraffic, 140000 );
00161         Add( _T("Connection.SendBuffer"), &Connection.SendBuffer, 2048 );
00162         Add( _T("Connection.AsyncIO"), &Connection.AsyncIO, TRUE );
00163         Add( _T("Connection.RequireForTransfers"), &Connection.RequireForTransfers, TRUE );
00164         Add( _T("Connection.ConnectThrottle"), &Connection.ConnectThrottle, 0 );
00165         Add( _T("Connection.DetectConnectionLoss"), &Connection.DetectConnectionLoss, TRUE );
00166         Add( _T("Connection.DetectConnectionReset"), &Connection.DetectConnectionReset, FALSE );
00167         Add( _T("Connection.ForceConnectedState"), &Connection.ForceConnectedState, TRUE );
00168         Add( _T("Connection.SlowConnect"), &Connection.SlowConnect, FALSE );
00169         
00170         Add( _T("Bandwidth.Request"), &Bandwidth.Request, 4096 );
00171         Add( _T("Bandwidth.HubIn"), &Bandwidth.HubIn, 0 );
00172         Add( _T("Bandwidth.HubOut"), &Bandwidth.HubOut, 0 );
00173         Add( _T("Bandwidth.LeafIn"), &Bandwidth.LeafIn, 0 );
00174         Add( _T("Bandwidth.LeafOut"), &Bandwidth.LeafOut, 0 );
00175         Add( _T("Bandwidth.PeerIn"), &Bandwidth.PeerIn, 0 );
00176         Add( _T("Bandwidth.PeerOut"), &Bandwidth.PeerOut, 0 );
00177         Add( _T("Bandwidth.UdpOut"), &Bandwidth.UdpOut, 0 );
00178         Add( _T("Bandwidth.Downloads"), &Bandwidth.Downloads, 0 );
00179         Add( _T("Bandwidth.Uploads"), &Bandwidth.Uploads, 0 );
00180         Add( _T("Bandwidth.HubUploads"), &Bandwidth.HubUploads, 5120 );
00181         
00182         Add( _T("Community.ChatEnable"), &Community.ChatEnable, TRUE );
00183         Add( _T("Community.ChatAllNetworks"), &Community.ChatAllNetworks, FALSE );
00184         Add( _T("Community.ChatFilter"), &Community.ChatFilter, FALSE );
00185         Add( _T("Community.ChatFilterED2K"), &Community.ChatFilterED2K, TRUE );
00186         Add( _T("Community.ChatCensor"), &Community.ChatCensor, FALSE );
00187 
00188         Add( _T("Community.Timestamp"), &Community.Timestamp, TRUE );
00189         Add( _T("Community.ServeProfile"), &Community.ServeProfile, TRUE );
00190         Add( _T("Community.ServeFiles"), &Community.ServeFiles, TRUE );
00191         
00192         Add( _T("Discovery.AccessThrottle"), &Discovery.AccessThrottle, 3600 );
00193         Add( _T("Discovery.Lowpoint"), &Discovery.Lowpoint, 10 );
00194         Add( _T("Discovery.FailureLimit"), &Discovery.FailureLimit, 2 );
00195         Add( _T("Discovery.UpdatePeriod"), &Discovery.UpdatePeriod, 1800 );
00196         Add( _T("Discovery.DefaultUpdate"), &Discovery.DefaultUpdate, 3600 );
00197         Add( _T("Discovery.BootstrapCount"), &Discovery.BootstrapCount, 10 );
00198         Add( _T("Discovery.G2DAddress"), &Discovery.G2DAddress, _T("stats.shareaza.com:6446") );
00199         Add( _T("Discovery.G2DRetryAfter"), &Discovery.G2DRetryAfter, 0 );
00200         Add( _T("Discovery.CacheCount"), &Discovery.CacheCount, 50 );
00201         
00202         Add( _T("Gnutella.ConnectFactor"), &Gnutella.ConnectFactor, 4 );
00203         Add( _T("Gnutella.DeflateHub2Hub"), &Gnutella.DeflateHub2Hub, TRUE );
00204         Add( _T("Gnutella.DeflateLeaf2Hub"), &Gnutella.DeflateLeaf2Hub, FALSE );
00205         Add( _T("Gnutella.DeflateHub2Leaf"), &Gnutella.DeflateHub2Leaf, TRUE );
00206         Add( _T("Gnutella.MaxResults"), &Gnutella.MaxResults, 100 );
00207         Add( _T("Gnutella.MaxHits"), &Gnutella.MaxHits, 64 );
00208         Add( _T("Gnutella.HitsPerPacket"), &Gnutella.HitsPerPacket, 64 );
00209         Add( _T("Gnutella.RouteCache"), &Gnutella.RouteCache, 600 );
00210         Add( _T("Gnutella.HostCacheCount"), &Gnutella.HostCacheSize, 1024 );
00211         Add( _T("Gnutella.HostCacheView"), &Gnutella.HostCacheView, PROTOCOL_ED2K );
00212         Add( _T("Gnutella.ConnectThrottle"), &Gnutella.ConnectThrottle, 120 );
00213         Add( _T("Gnutella.BlockBlankClients"), &Gnutella.BlockBlankClients, TRUE );
00214         Add( _T("Gnutella.SpecifyProtocol"), &Gnutella.SpecifyProtocol, FALSE );
00215         
00216         Add( _T("Gnutella1.ClientMode"), &Gnutella1.ClientMode, MODE_LEAF );
00217         Add( _T("Gnutella1.EnableAlways"), &Gnutella1.EnableAlways, FALSE );
00218         Add( _T("Gnutella1.NumHubs"), &Gnutella1.NumHubs, 2 );
00219         Add( _T("Gnutella1.NumLeafs"), &Gnutella1.NumLeafs, 0 );
00220         Add( _T("Gnutella1.NumPeers"), &Gnutella1.NumPeers, 0 );
00221         Add( _T("Gnutella1.PacketBufferSize"), &Gnutella1.PacketBufferSize, 64 );
00222         Add( _T("Gnutella1.PacketBufferTime"), &Gnutella1.PacketBufferTime, 60000 );
00223         Add( _T("Gnutella1.DefaultTTL"), &Gnutella1.DefaultTTL, 5 );
00224         Add( _T("Gnutella1.SearchTTL"), &Gnutella1.SearchTTL, 4 );
00225         Add( _T("Gnutella1.TranslateTTL"), &Gnutella1.TranslateTTL, 2 );
00226         Add( _T("Gnutella1.MaximumTTL"), &Gnutella1.MaximumTTL, 10 );
00227         Add( _T("Gnutella1.MaximumPacket"), &Gnutella1.MaximumPacket, 65535 );
00228         Add( _T("Gnutella1.MaximumQuery"), &Gnutella1.MaximumQuery, 256 );
00229         Add( _T("Gnutella1.StrictPackets"), &Gnutella1.StrictPackets, FALSE );
00230         Add( _T("Gnutella1.EnableGGEP"), &Gnutella1.EnableGGEP, TRUE );
00231         Add( _T("Gnutella1.VendorMsg"), &Gnutella1.VendorMsg, TRUE );
00232         Add( _T("Gnutella1.QueryThrottle"), &Gnutella1.QueryThrottle, 20*60 );
00233         Add( _T("Gnutella1.RequeryDelay"), &Gnutella1.RequeryDelay, 45*60 );
00234         Add( _T("Gnutella1.HostExpire"), &Gnutella1.HostExpire, 2 * 24 * 60 * 60 );
00235         Add( _T("Gnutella1.PingFlood"), &Gnutella1.PingFlood, 3000 );
00236         Add( _T("Gnutella1.PingRate"), &Gnutella1.PingRate, 15000 );
00237         Add( _T("Gnutella1.PongCache"), &Gnutella1.PongCache, 10000 );
00238         Add( _T("Gnutella1.PongCount"), &Gnutella1.PongCount, 10 );
00239         Add( _T("Gnutella1.QueueLimter"), &Gnutella1.HitQueueLimit, 50 );
00240         Add( _T("Gnutella1.QuerySearchUTF8"), &Gnutella1.QuerySearchUTF8, FALSE );
00241         Add( _T("Gnutella1.QueryHitUTF8"), &Gnutella1.QueryHitUTF8, FALSE );
00242 
00243         Add( _T("Gnutella2.ClientMode"), &Gnutella2.ClientMode, MODE_AUTO );
00244         Add( _T("Gnutella2.HubVerified"), &Gnutella2.HubVerified, FALSE );
00245         Add( _T("Gnutella2.EnableAlways"), &Gnutella2.EnableAlways, TRUE );
00246         Add( _T("Gnutella2.NumHubs"), &Gnutella2.NumHubs, 2 );
00247         Add( _T("Gnutella2.NumLeafs"), &Gnutella2.NumLeafs, 300 );
00248         Add( _T("Gnutella2.NumPeers"), &Gnutella2.NumPeers, 6 );
00249         Add( _T("Gnutella2.PingRelayLimit"), &Gnutella2.PingRelayLimit, 10);
00250         Add( _T("Gnutella2.UdpMTU"), &Gnutella2.UdpMTU, 500 );
00251         Add( _T("Gnutella2.UdpBuffers"), &Gnutella2.UdpBuffers, 512 );
00252         Add( _T("Gnutella2.UdpInFrames"), &Gnutella2.UdpInFrames, 256 );
00253         Add( _T("Gnutella2.UdpOutFrames"), &Gnutella2.UdpOutFrames, 256 );
00254         Add( _T("Gnutella2.UdpGlobalThrottle"), &Gnutella2.UdpGlobalThrottle, 1 );
00255         Add( _T("Gnutella2.UdpOutExpire"), &Gnutella2.UdpOutExpire, 26000 );
00256         Add( _T("Gnutella2.UdpOutResend"), &Gnutella2.UdpOutResend, 6000 );
00257         Add( _T("Gnutella2.UdpInExpire"), &Gnutella2.UdpInExpire, 30000 );
00258         Add( _T("Gnutella2.KHLPeriod"), &Gnutella2.KHLPeriod, 60000 );
00259         Add( _T("Gnutella2.KHLHubCount"), &Gnutella2.KHLHubCount, 50 );
00260         Add( _T("Gnutella2.HAWPeriod"), &Gnutella2.HAWPeriod, 300000 );
00261         Add( _T("Gnutella2.HostExpire"), &Gnutella2.HostExpire, 0 );
00262         Add( _T("Gnutella2.HostCurrent"), &Gnutella2.HostCurrent, 10 * 60 );
00263         Add( _T("Gnutella2.QueryGlobalThrottle"), &Gnutella2.QueryGlobalThrottle, 125 );
00264         Add( _T("Gnutella2.QueryHostThrottle"), &Gnutella2.QueryHostThrottle, 120 );
00265         Add( _T("Gnutella2.QueryHostDeadline"), &Gnutella2.QueryHostDeadline, 10*60 );
00266         Add( _T("Gnutella2.RequeryDelay"), &Gnutella2.RequeryDelay, 4*60*60 );
00267         Add( _T("Gnutella2.HubHorizonSize"), &Gnutella2.HubHorizonSize, 128 );
00268         Add( _T("Gnutella2.QueryLimit"), &Gnutella2.QueryLimit, 2400 );
00269         
00270         Add( _T("eDonkey.EnableAlways"), &eDonkey.EnableAlways, FALSE );
00271         Add( _T("eDonkey.FastConnect"), &eDonkey.FastConnect, TRUE );
00272         Add( _T("eDonkey.NumServers"), &eDonkey.NumServers, 1 );
00273         Add( _T("eDonkey.MaxLinks"), &eDonkey.MaxLinks, 200 );
00274         Add( _T("eDonkey.MaxResults"), &eDonkey.MaxResults, 100 );
00275         Add( _T("eDonkey.MaxShareCount"), &eDonkey.MaxShareCount, 1000 );
00276         Add( _T("eDonkey.ServerWalk"), &eDonkey.ServerWalk, TRUE );
00277         Add( _T("eDonkey.StatsServerThrottle"), &eDonkey.StatsServerThrottle, 7*24*60*60 );
00278         Add( _T("eDonkey.StatsGlobalThrottle"), &eDonkey.StatsGlobalThrottle, 30*60*1000 );
00279         Add( _T("eDonkey.QueryGlobalThrottle"), &eDonkey.QueryGlobalThrottle, 1000 );
00280         Add( _T("eDonkey.QueryServerThrottle"), &eDonkey.QueryServerThrottle, 120 );
00281         Add( _T("eDonkey.QueryFileThrottle"), &eDonkey.QueryFileThrottle, 60*60*1000 );
00282         Add( _T("eDonkey.GetSourcesThrottle"), &eDonkey.GetSourcesThrottle, 8*60*60*1000 );
00283         Add( _T("eDonkey.QueueRankThrottle"), &eDonkey.QueueRankThrottle, 2*60*1000 );
00284         Add( _T("eDonkey.PacketThrottle"), &eDonkey.PacketThrottle, 500 );
00285         Add( _T("eDonkey.SourceThrottle"), &eDonkey.SourceThrottle, 1000 );
00286         Add( _T("eDonkey.MetAutoQuery"), &eDonkey.MetAutoQuery, FALSE );
00287         Add( _T("eDonkey.LearnNewServers"), &eDonkey.LearnNewServers, TRUE );
00288         Add( _T("eDonkey.LearnNewServersClient"), &eDonkey.LearnNewServersClient, FALSE );
00289         Add( _T("eDonkey.ServerListURL"), &eDonkey.ServerListURL, _T("http://ocbmaurice.dyndns.org/pl/slist.pl/server.met?download/server-good.met") );
00290         Add( _T("eDonkey.RequestPipe"), &eDonkey.RequestPipe, 3 );
00291         Add( _T("eDonkey.RequestSize"), &eDonkey.RequestSize, 180*1024/2 );
00292         Add( _T("eDonkey.FrameSize"), &eDonkey.FrameSize, 10240 );
00293         Add( _T("eDonkey.ReAskTime"), &eDonkey.ReAskTime, 1740 );
00294         Add( _T("eDonkey.DequeueTime"), &eDonkey.DequeueTime, 3610 );
00295         Add( _T("eDonkey.TagNames"), &eDonkey.TagNames, TRUE );
00296         Add( _T("eDonkey.ExtendedRequest"), &eDonkey.ExtendedRequest, TRUE );
00297         Add( _T("eDonkey.MagnetSearch"), &eDonkey.MagnetSearch, TRUE );
00298         Add( _T("eDonkey.MinServerFileSize"), &eDonkey.MinServerFileSize, 0 );
00299         Add( _T("eDonkey.DefaultServerFlags"), &eDonkey.DefaultServerFlags, 0xFFFFFFFF );       
00300         Add( _T("eDonkey.Endgame"), &eDonkey.Endgame, TRUE );
00301         
00302         Add( _T("BitTorrent.AdvancedInterface"), &BitTorrent.AdvancedInterface, FALSE );
00303         Add( _T("BitTorrent.AdvancedInterfaceSet"), &BitTorrent.AdvancedInterfaceSet, FALSE );
00304         Add( _T("BitTorrent.TorrentCreatorPath"), &BitTorrent.TorrentCreatorPath, _T("") );
00305         Add( _T("BitTorrent.DefaultTracker"), &BitTorrent.DefaultTracker, _T("") );
00306         Add( _T("BitTorrent.DefaultTrackerPeriod"), &BitTorrent.DefaultTrackerPeriod, 5*60000 );
00307         Add( _T("BitTorrent.MaxTrackerRetry"), &BitTorrent.MaxTrackerRetry, 3 );
00308         Add( _T("BitTorrent.TorrentCodePage"), &BitTorrent.TorrentCodePage, 0 );
00309         Add( _T("BitTorrent.TorrentExtraKeys"), &BitTorrent.TorrentExtraKeys, TRUE );
00310         Add( _T("BitTorrent.TorrentIgnoreErrors"), &BitTorrent.TorrentIgnoreErrors, FALSE );
00311         Add( _T("BitTorrent.LinkTimeout"), &BitTorrent.LinkTimeout, 180000 );
00312         Add( _T("BitTorrent.LinkPing"), &BitTorrent.LinkPing, 45000 );
00313         Add( _T("BitTorrent.RequestPipe"), &BitTorrent.RequestPipe, 4 );
00314         Add( _T("BitTorrent.RequestSize"), &BitTorrent.RequestSize, 16384 );
00315         Add( _T("BitTorrent.RequestLimit"), &BitTorrent.RequestLimit, 131072 );
00316         Add( _T("BitTorrent.RandomPeriod"), &BitTorrent.RandomPeriod, 30000 );
00317         Add( _T("BitTorrent.SourceExchangePeriod"), &BitTorrent.SourceExchangePeriod, 10 );
00318         Add( _T("BitTorrent.UploadCount"), &BitTorrent.UploadCount, 4 );
00319         Add( _T("BitTorrent.DownloadConnections"), &BitTorrent.DownloadConnections, 40 );
00320         Add( _T("BitTorrent.DownloadTorrents"), &BitTorrent.DownloadTorrents, 3 );
00321         Add( _T("BitTorrent.Endgame"), &BitTorrent.Endgame, TRUE );
00322         Add( _T("BitTorrent.AutoClear"), &BitTorrent.AutoClear, FALSE );
00323         Add( _T("BitTorrent.ClearRatio"), &BitTorrent.ClearRatio, 120 );
00324         Add( _T("BitTorrent.AutoSeed"), &BitTorrent.AutoSeed, FALSE );
00325         Add( _T("BitTorrent.BandwidthPercentage"), &BitTorrent.BandwidthPercentage, 80 );
00326         Add( _T("BitTorrent.TrackerKey"), &BitTorrent.TrackerKey, TRUE );
00327         Add( _T("BitTorrent.StandardPeerID"), &BitTorrent.StandardPeerID, TRUE );
00328         Add( _T("BitTorrent.PreferenceBTSources"), &BitTorrent.PreferenceBTSources, TRUE );
00329         
00330         Add( _T("Downloads.IncompletePath"), &Downloads.IncompletePath, General.UserPath + _T("\\Incomplete") );
00331         Add( _T("Downloads.CompletePath"), &Downloads.CompletePath, General.UserPath + _T("\\Downloads") );
00332         Add( _T("Downloads.TorrentPath"), &Downloads.TorrentPath, General.UserPath + _T("\\Torrents") );
00333         Add( _T("Downloads.CollectionPath"), &Downloads.CollectionPath, General.UserPath + _T("\\Collections") );
00334         Add( _T("Downloads.BufferSize"), &Downloads.BufferSize, 81920 );
00335         Add( _T("Downloads.SparseThreshold"), &Downloads.SparseThreshold, 8 * 1024 );
00336         Add( _T("Downloads.MaxFiles"), &Downloads.MaxFiles, 32 );
00337         Add( _T("Downloads.MaxTransfers"), &Downloads.MaxTransfers, 128 );
00338         Add( _T("Downloads.MaxFileTransfers"), &Downloads.MaxFileTransfers, 8 );
00339         Add( _T("Downloads.MaxFileSearches"), &Downloads.MaxFileSearches, 0 );
00340         Add( _T("Downloads.MaxConnectingSources"), &Downloads.MaxConnectingSources, 30 );
00341         Add( _T("Downloads.MinSources"), &Downloads.MinSources, 1 );
00342         Add( _T("Downloads.ConnectThrottle"), &Downloads.ConnectThrottle, 250 );
00343         Add( _T("Downloads.QueueLimit"), &Downloads.QueueLimit, 0 );
00344         Add( _T("Downloads.SearchPeriod"), &Downloads.SearchPeriod, 120000 );
00345         Add( _T("Downloads.StarveTimeout"), &Downloads.StarveTimeout, 2700 );
00346         Add( _T("Downloads.StarveGiveUp"), &Downloads.StarveGiveUp, 3 );
00347         Add( _T("Downloads.RetryDelay"), &Downloads.RetryDelay, 10*60000 );
00348         Add( _T("Downloads.PushTimeout"), &Downloads.PushTimeout, 45000 );
00349         Add( _T("Downloads.StaggardStart"), &Downloads.StaggardStart, FALSE );
00350         Add( _T("Downloads.AllowBackwards"), &Downloads.AllowBackwards, TRUE );
00351         Add( _T("Downloads.ChunkSize"), &Downloads.ChunkSize, 512*1024 );
00352         Add( _T("Downloads.ChunkStrap"), &Downloads.ChunkStrap, 128*1024 );
00353         Add( _T("Downloads.Metadata"), &Downloads.Metadata, TRUE );
00354         Add( _T("Downloads.VerifyFiles"), &Downloads.VerifyFiles, TRUE );
00355         Add( _T("Downloads.VerifyTiger"), &Downloads.VerifyTiger, TRUE );
00356         Add( _T("Downloads.VerifyED2K"), &Downloads.VerifyED2K, TRUE );
00357         Add( _T("Downloads.NeverDrop"), &Downloads.NeverDrop, FALSE );
00358         Add( _T("Downloads.RequestHash"), &Downloads.RequestHash, FALSE );
00359         Add( _T("Downloads.RequestHTTP11"), &Downloads.RequestHTTP11, TRUE );
00360         Add( _T("Downloads.RequestURLENC"), &Downloads.RequestURLENC, TRUE );
00361         Add( _T("Downloads.SaveInterval"), &Downloads.SaveInterval, 60000 );
00362         Add( _T("Downloads.FlushSD"), &Downloads.FlushSD, TRUE );
00363         Add( _T("Downloads.ShowSources"), &Downloads.ShowSources, FALSE );
00364         Add( _T("Downloads.SimpleBar"), &Downloads.SimpleBar, FALSE );
00365         Add( _T("Downloads.ShowPercent"), &Downloads.ShowPercent, FALSE );
00366         Add( _T("Downloads.ShowGroups"), &Downloads.ShowGroups, TRUE );
00367         Add( _T("Downloads.AutoExpand"), &Downloads.AutoExpand, FALSE );
00368         Add( _T("Downloads.AutoClear"), &Downloads.AutoClear, FALSE );
00369         Add( _T("Downloads.ClearDelay"), &Downloads.ClearDelay, 30000 );
00370         Add( _T("Downloads.FilterMask"), &Downloads.FilterMask, 0xFFFFFFFF );
00371         Add( _T("Downloads.ShowMonitorURLs"), &Downloads.ShowMonitorURLs, TRUE );
00372         Add( _T("Downloads.SortColumns"), &Downloads.SortColumns, TRUE );
00373         Add( _T("Downloads.SortSources"), &Downloads.SortSources, TRUE );
00374         Add( _T("Downloads.SourcesWanted"), &Downloads.SourcesWanted, 500 );
00375         Add( _T("Downloads.MaxReviews"), &Downloads.MaxReviews, 64 );
00376 
00377         Add( _T("Uploads.MaxPerHost"), &Uploads.MaxPerHost, 2 );
00378         Add( _T("Uploads.FreeBandwidthValue"), &Uploads.FreeBandwidthValue, 2560 );
00379         Add( _T("Uploads.FreeBandwidthFactor"), &Uploads.FreeBandwidthFactor, 15 );
00380         Add( _T("Uploads.ClampdownFactor"), &Uploads.ClampdownFactor, 20 );
00381         Add( _T("Uploads.ClampdownFloor"), &Uploads.ClampdownFloor, 1024 );
00382         Add( _T("Uploads.ThrottleMode"), &Uploads.ThrottleMode, TRUE );
00383         Add( _T("Uploads.QueuePollMin"), &Uploads.QueuePollMin, 45000 );
00384         Add( _T("Uploads.QueuePollMax"), &Uploads.QueuePollMax, 120000 );
00385         Add( _T("Uploads.RotateChunkLimit"), &Uploads.RotateChunkLimit, 1024*1024 );
00386         Add( _T("Uploads.SharePartials"), &Uploads.SharePartials, TRUE );
00387         Add( _T("Uploads.ShareTiger"), &Uploads.ShareTiger, TRUE );
00388         Add( _T("Uploads.ShareHashset"), &Uploads.ShareHashset, TRUE );
00389         Add( _T("Uploads.ShareMetadata"), &Uploads.ShareMetadata, TRUE );
00390         Add( _T("Uploads.SharePreviews"), &Uploads.SharePreviews, TRUE );
00391         Add( _T("Uploads.DynamicPreviews"), &Uploads.DynamicPreviews, TRUE );
00392         Add( _T("Uploads.PreviewQuality"), &Uploads.PreviewQuality, 40 );
00393         Add( _T("Uploads.PreviewTransfers"), &Uploads.PreviewTransfers, 3 );
00394         Add( _T("Uploads.AllowBackwards"), &Uploads.AllowBackwards, TRUE );
00395         Add( _T("Uploads.HubUnshare"), &Uploads.HubUnshare, TRUE );
00396         Add( _T("Uploads.BlockAgents"), &Uploads.BlockAgents, _T("|Mozilla|") );
00397         Add( _T("Uploads.AutoClear"), &Uploads.AutoClear, FALSE );
00398         Add( _T("Uploads.ClearDelay"), &Uploads.ClearDelay, 30000 );
00399         Add( _T("Uploads.FilterMask"), &Uploads.FilterMask, 0xFFFFFFFD );
00400         Add( _T("Uploads.RewardQueuePercentage"), &Uploads.RewardQueuePercentage, 10 );
00401         
00402         Add( _T("Remote.Enable"), &Remote.Enable, FALSE );
00403         Add( _T("Remote.Username"), &Remote.Username, _T("") );
00404         Add( _T("Remote.Password"), &Remote.Password, _T("") );
00405 
00406         Add( _T("Scheduler.Enable"), &Scheduler.Enable, FALSE );
00407         Add( _T("Scheduler.LimitedBandwidth"), &Scheduler.LimitedBandwidth, 50 );
00408         Add( _T("Scheduler.LimitedNetworks"), &Scheduler.LimitedNetworks, TRUE );
00409         Add( _T("Scheduler.AllowHub"), &Scheduler.AllowHub, TRUE );
00410 }
00411 
00412 
00413 
00415 // CSettings construction
00416 
00417 CSettings::CSettings()
00418 {
00419         TCHAR szPath[128];
00420         GetModuleFileName( NULL, szPath, 128 );
00421         
00422         // Set default program and user paths
00423         General.Path = szPath;
00424         if ( General.Path.ReverseFind( '\\' ) >= 0 )
00425                 General.Path = General.Path.Left( General.Path.ReverseFind( '\\' ) );
00426         General.UserPath = General.Path;
00427         
00428         // Reset 'live' values.
00429 
00430         Live.DiskSpaceWarning   = FALSE;
00431         Live.DiskWriteWarning   = FALSE;
00432         Live.AdultWarning               = FALSE;
00433         Live.QueueLimitWarning  = FALSE;
00434         Live.DonkeyServerWarning= FALSE;
00435         Live.UploadLimitWarning = FALSE;
00436         Live.DiskSpaceStop              = FALSE;
00437         Live.BandwidthScale             = 100;
00438         Live.LoadWindowState    = FALSE;
00439         Live.AutoClose                  = FALSE;
00440         Live.FirstRun                   = FALSE;
00441 
00442         // Add all settings
00443         Setup();
00444 }
00445 
00446 CSettings::~CSettings()
00447 {
00448         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00449         {
00450                 delete (Item*)m_pItems.GetNext( pos );
00451         }
00452 }
00453 
00455 // CSettings add items
00456 
00457 void CSettings::Add(LPCTSTR pszName, DWORD* pDword, DWORD nDefault)
00458 {
00459         m_pItems.AddTail( new Item( pszName, pDword, NULL, NULL ) );
00460         *pDword = nDefault;
00461 }
00462 
00463 void CSettings::Add(LPCTSTR pszName, int* pDword, DWORD nDefault)
00464 {
00465         m_pItems.AddTail( new Item( pszName, (DWORD*)pDword, NULL, NULL ) );
00466         *pDword = nDefault;
00467 }
00468 
00469 void CSettings::Add(LPCTSTR pszName, DOUBLE* pFloat, DOUBLE nDefault)
00470 {
00471         m_pItems.AddTail( new Item( pszName, NULL, pFloat, NULL ) );
00472         *pFloat = nDefault;
00473 }
00474 
00475 void CSettings::Add(LPCTSTR pszName, CString* pString, LPCTSTR pszDefault)
00476 {
00477         m_pItems.AddTail( new Item( pszName, NULL, NULL, pString ) );
00478         if ( pszDefault ) *pString = pszDefault;
00479 }
00480 
00482 // CSettings load
00483 
00484 #define SMART_VERSION   31
00485 
00486 void CSettings::Load()
00487 {
00488         CRegistry pRegistry;
00489         
00490         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00491         {
00492                 Item* pItem = (Item*)m_pItems.GetNext( pos );
00493                 pItem->Load();
00494         }
00495         
00496         if ( pRegistry.GetInt( _T("Settings"), _T("FirstRun"), TRUE ) )
00497         {
00498                 Live.FirstRun = TRUE;
00499                 pRegistry.SetInt( _T("Settings"), _T("FirstRun"), FALSE );
00500         }
00501         
00502         SmartUpgrade();
00503         
00504         if ( pRegistry.GetInt( _T("Settings"), _T("Running"), FALSE ) )
00505         {
00506                 //pRegistry.SetInt( _T("VersionCheck"), _T("NextCheck"), 0 );
00507         }
00508         else
00509         {
00510                 pRegistry.SetInt( _T("Settings"), _T("Running"), TRUE );
00511         }
00512         
00513         // Set current networks
00514         Gnutella1.EnableToday           = Gnutella1.EnableAlways;
00515         Gnutella2.EnableToday           = Gnutella2.EnableAlways;
00516         eDonkey.EnableToday                     = eDonkey.EnableAlways;
00517         
00518         // Make sure some needed paths exist
00519         CreateDirectory( General.Path + _T("\\Data"), NULL );
00520         CreateDirectory( General.UserPath + _T("\\Data"), NULL );
00521 
00522         // Set interface
00523         Interface.LowResMode            = ! ( GetSystemMetrics( SM_CYSCREEN ) > 600 );
00524         if ( Live.FirstRun ) Search.AdvancedPanel = ! Interface.LowResMode;
00525 
00526         // Reset certain network variables if bandwidth is too low
00527         // Set ed2k and G1
00528         if ( GetOutgoingBandwidth() < 2 ) 
00529         {
00530                 eDonkey.EnableToday             = FALSE;
00531                 eDonkey.EnableAlways    = FALSE;
00532                 Gnutella1.EnableToday   = FALSE;
00533                 Gnutella1.EnableAlways  = FALSE;
00534         }
00535         // Set number of torrents
00536         BitTorrent.DownloadTorrents = min( BitTorrent.DownloadTorrents, (int)( ( GetOutgoingBandwidth() / 2 ) + 2 ) );
00537 
00538         // Enforce a few sensible values to avoid being banned/dropped/etc (in case of registry fiddling)
00539         Downloads.SearchPeriod          = min( Downloads.SearchPeriod, DWORD(4*60*1000) );
00540         Downloads.StarveTimeout         = max( Downloads.StarveTimeout, DWORD(45*60) );
00541         eDonkey.QueryGlobalThrottle = max( eDonkey.QueryGlobalThrottle, DWORD(1000) );
00542         Gnutella1.RequeryDelay          = max( Gnutella1.RequeryDelay, DWORD(45*60) );
00543         Gnutella2.RequeryDelay          = max( Gnutella2.RequeryDelay, DWORD(60*60) );
00544         Downloads.ConnectThrottle       = max( Downloads.ConnectThrottle, Connection.ConnectThrottle + 50 );
00545         Downloads.MaxFiles                      = min( Downloads.MaxFiles, 100 );
00546 
00547         // Set client links
00548         Gnutella1.NumHubs                       = min( Gnutella1.NumHubs, 2 );
00549         Gnutella2.NumHubs                       = min( Gnutella2.NumHubs, 3 );
00550         Gnutella2.NumLeafs                      = min( Gnutella2.NumLeafs, 1024 );
00551 
00552         // Make sure download/incomplete folders aren't the same
00553         if ( _tcsicmp( Downloads.IncompletePath, Downloads.CompletePath ) == 0 )
00554         {
00555                 CString strMessage;
00556                 LoadString( strMessage, IDS_SETTINGS_FILEPATH_NOT_SAME );
00557                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00558                 // Downloads.IncompletePath = General.Path + _T("\\Incomplete");
00559         }
00560 
00561         //Temporary- until G1 ultrapeer has been updated
00562         Gnutella1.ClientMode            = MODE_LEAF; 
00563 }
00564 
00565 void CSettings::Save(BOOL bShutdown)
00566 {
00567         CRegistry pRegistry;
00568         
00569         if ( Connection.TimeoutConnect == 0 ) return;
00570         
00571         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00572         {
00573                 Item* pItem = (Item*)m_pItems.GetNext( pos );
00574                 if ( pItem->m_sName != _T(".Path") ) pItem->Save();
00575         }
00576         
00577         pRegistry.SetInt( _T("Settings"), _T("SmartVersion"), SMART_VERSION );
00578         pRegistry.SetInt( _T("Settings"), _T("Running"), bShutdown ? FALSE : TRUE );
00579 }
00580 
00582 // CSettings smart upgrade
00583 
00584 void CSettings::SmartUpgrade()
00585 {       //This function resets certain values when upgrading, depending on version.
00586         CRegistry pRegistry;
00587         int nVersion = pRegistry.GetInt( _T("Settings"), _T("SmartVersion"), SMART_VERSION );
00588 
00589         // Set next update check
00590         if ( nVersion < SMART_VERSION )
00591         {
00592                 // Don't check for a week if we've just upgraded
00593                 CTimeSpan tPeriod( 7, 0, 0, 0 );
00594                 CTime tNextCheck = CTime::GetCurrentTime() + tPeriod;
00595                 theApp.WriteProfileInt( _T("VersionCheck"), _T("NextCheck"), (DWORD)tNextCheck.GetTime() );
00596         }
00597         
00598         // Add OGG handling if needed
00599         if ( ( nVersion < SMART_VERSION || Live.FirstRun ) &&
00600                 _tcsistr( MediaPlayer.FileTypes, _T("|ogg|") ) == NULL )
00601         {
00602                 LONG nReg = 0;
00603                 
00604                 if ( RegQueryValue( HKEY_CLASSES_ROOT,
00605                         _T("CLSID\\{02391F44-2767-4E6A-A484-9B47B506F3A4}"), NULL, &nReg )
00606                         == ERROR_SUCCESS && nReg > 0 )
00607                 {
00608                         MediaPlayer.FileTypes += _T("|ogg|");
00609                 }
00610         }
00611         
00612         // 'SmartUpgrade' settings updates- change any settings that were mis-set in previous versions
00613         if ( nVersion < 20 )
00614         {
00615                 Gnutella1.RequeryDelay                  = 45*60;
00616                 Gnutella2.UdpOutResend                  = 6000;
00617                 Gnutella2.UdpOutExpire                  = 26000;
00618                 Library.TigerHeight             = 9;
00619                 Library.BitziWebSubmit  = _T("http://bitzi.com/lookup/(SHA1).(TTH)?fl=(SIZE)&ff=(FIRST20)&fn=(NAME)&a=(AGENT)&v=Q0.4&ref=shareaza");
00620                 Downloads.MaxFiles                              = max( Downloads.MaxFiles, 8 );
00621                 Downloads.MaxFileTransfers              = max( Downloads.MaxFileTransfers, 16 );
00622                 Downloads.AutoExpand                    = FALSE;
00623                 Uploads.SharePartials                   = TRUE;
00624                 Uploads.MaxPerHost                              = 2;
00625                 Uploads.ShareTiger                              = TRUE;
00626                 Replace( Library.PrivateTypes, _T("|nfo|"), _T("|") );
00627                 Replace( Library.SafeExecute, _T("|."), _T("|") );
00628         }
00629         
00630         if ( nVersion < 21 )
00631         {
00632                 Library.ThumbSize                               = 96;
00633                 Library.SourceExpire                    = 86400;
00634                 Gnutella1.TranslateTTL                  = 2;
00635         }
00636         
00637         if ( nVersion < 24 )
00638         {
00639                 General.CloseMode                               = 0;
00640                 Connection.TimeoutConnect               = 16000;
00641                 Connection.TimeoutHandshake             = 45000;
00642                 Downloads.RetryDelay                    = 10*60000;
00643                 Uploads.FilterMask                              = 0xFFFFFFFD;
00644         }
00645         
00646         if ( nVersion < 25 )
00647         {
00648                 Connection.TimeoutTraffic               = 140000;
00649                 Gnutella2.NumHubs                               = 2;
00650                 Gnutella2.NumLeafs                              = 300;
00651                 Gnutella2.NumPeers                              = 6;
00652         }
00653         
00654         if ( nVersion < 26 )
00655         {
00656                 Downloads.ConnectThrottle               = max( Downloads.ConnectThrottle, DWORD(200) );
00657                 Downloads.MaxTransfers                  = min( Downloads.MaxTransfers, 128 );
00658         }
00659         
00660         if ( nVersion < 28 )
00661         {
00662                 Library.VirtualFiles    = TRUE;         // Virtual files (stripping) on 
00663                 BitTorrent.Endgame              = TRUE;         // Endgame on
00664         }
00665 
00666         if ( nVersion < 29 )
00667         {
00668                 Downloads.MinSources    = 1;            // Lower Max value- should reset it in case  
00669                 Downloads.StarveTimeout = 2700;         // Increased due to ed2k queues (Tripping too often)
00670                 Gnutella.MaxResults             = 100;          // No longer includes ed2k max files
00671                 Gnutella2.RequeryDelay  = 4*3600;       // Longer delay between sending same search to G2 hub
00672         }
00673 
00674         if ( nVersion < 30 )
00675         {
00676                 BitTorrent.RequestSize  = 16384;        // Other BT clients have changed this value (undocumented) 
00677         }
00678 
00679         if ( nVersion < 31 )
00680         {
00681                 Downloads.SearchPeriod  = 120000;
00682                 Gnutella1.MaximumTTL    = 10;
00683                 Gnutella2.QueryGlobalThrottle = 125;
00684                 Uploads.QueuePollMin    = 45000;        // Lower values for re-ask times- a dynamic multiplier
00685                 Uploads.QueuePollMax    = 120000;       // Is now applied based on Q# (from 1x to 5x)
00686                 eDonkey.PacketThrottle  = 500;          // Second throttle added for finer control
00687         }
00688 
00689 }
00690 
00692 // CSettings settings lookup
00693 
00694 CSettings::Item* CSettings::GetSetting(LPCTSTR pszName) const
00695 {
00696         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00697         {
00698                 Item* pItem = (Item*)m_pItems.GetNext( pos );
00699                 if ( pItem->m_sName.CompareNoCase( pszName ) == 0 ) return pItem;
00700         }
00701         
00702         return NULL;
00703 }
00704 
00705 CSettings::Item* CSettings::GetSetting(LPVOID pValue) const
00706 {
00707         for ( POSITION pos = m_pItems.GetHeadPosition() ; pos ; )
00708         {
00709                 Item* pItem = (Item*)m_pItems.GetNext( pos );
00710                 if ( pItem->m_pDword == pValue ||
00711                          pItem->m_pFloat == pValue ||
00712                          pItem->m_pString == pValue ) return pItem;
00713         }
00714 
00715         return NULL;
00716 }
00717 
00719 // CSettings window position persistance
00720 
00721 BOOL CSettings::LoadWindow(LPCTSTR pszName, CWnd* pWindow)
00722 {
00723         WINDOWPLACEMENT pPos;
00724         CRegistry pRegistry;
00725         CString strEntry;
00726         
00727         if ( pszName != NULL )
00728                 strEntry = pszName;
00729         else
00730                 strEntry = pWindow->GetRuntimeClass()->m_lpszClassName;
00731         
00732         int nShowCmd = pRegistry.GetInt( _T("Windows"), strEntry + _T(".ShowCmd"), -1 );
00733         if ( nShowCmd == -1 ) return FALSE;
00734         
00735         ZeroMemory( &pPos, sizeof(pPos) );
00736         pPos.length = sizeof(pPos);
00737 
00738         pPos.rcNormalPosition.left              = pRegistry.GetInt( _T("Windows"), strEntry + _T(".Left"), 0 );
00739         pPos.rcNormalPosition.top               = pRegistry.GetInt( _T("Windows"), strEntry + _T(".Top"), 0 );
00740         pPos.rcNormalPosition.right             = pRegistry.GetInt( _T("Windows"), strEntry + _T(".Right"), 0 );
00741         pPos.rcNormalPosition.bottom    = pRegistry.GetInt( _T("Windows"), strEntry + _T(".Bottom"), 0 );
00742         
00743         if ( pPos.rcNormalPosition.right && pPos.rcNormalPosition.bottom )
00744         {
00745                 pPos.showCmd = 0;
00746                 pWindow->SetWindowPlacement( &pPos );
00747         }
00748         
00749         if ( Live.LoadWindowState && nShowCmd == SW_SHOWMINIMIZED )
00750         {
00751                 pWindow->PostMessage( WM_SYSCOMMAND, SC_MINIMIZE );
00752         }
00753         else if ( ! Live.LoadWindowState && nShowCmd == SW_SHOWMAXIMIZED )
00754         {
00755                 pWindow->PostMessage( WM_SYSCOMMAND, SC_MAXIMIZE );
00756         }
00757         
00758         return TRUE;
00759 }
00760 
00761 void CSettings::SaveWindow(LPCTSTR pszName, CWnd* pWindow)
00762 {
00763         WINDOWPLACEMENT pPos;
00764         CRegistry pRegistry;
00765         CString strEntry;
00766 
00767         if ( pszName != NULL )
00768                 strEntry = pszName;
00769         else
00770                 strEntry = pWindow->GetRuntimeClass()->m_lpszClassName;
00771 
00772         pWindow->GetWindowPlacement( &pPos );
00773 
00774         pRegistry.SetInt(  _T("Windows"), strEntry + _T(".ShowCmd"), pPos.showCmd );
00775 
00776         if ( pPos.showCmd != SW_SHOWNORMAL ) return;
00777 
00778         pRegistry.SetInt(  _T("Windows"), strEntry + _T(".Left"), pPos.rcNormalPosition.left );
00779         pRegistry.SetInt(  _T("Windows"), strEntry + _T(".Top"), pPos.rcNormalPosition.top );
00780         pRegistry.SetInt(  _T("Windows"), strEntry + _T(".Right"), pPos.rcNormalPosition.right );
00781         pRegistry.SetInt(  _T("Windows"), strEntry + _T(".Bottom"), pPos.rcNormalPosition.bottom );
00782 
00783 }
00784 
00786 // CSettings list header persistance
00787 
00788 BOOL CSettings::LoadList(LPCTSTR pszName, CListCtrl* pCtrl, int nSort)
00789 {
00790         CRegistry pRegistry;
00791         LV_COLUMN pColumn;
00792         
00793         pColumn.mask = LVCF_FMT;
00794     int nColumns = 0;
00795         for ( ; pCtrl->GetColumn( nColumns, &pColumn ) ; nColumns++ );
00796         
00797         CString strOrdering, strWidths, strItem;
00798         BOOL bSuccess = FALSE;
00799         
00800         strItem.Format( _T("%s.Ordering"), pszName );
00801         strOrdering = pRegistry.GetString( _T("ListStates"), strItem, _T("") );
00802         strItem.Format( _T("%s.Widths"), pszName );
00803         strWidths = pRegistry.GetString( _T("ListStates"), strItem, _T("") );
00804         strItem.Format( _T("%s.Sort"), pszName );
00805         nSort = pRegistry.GetInt( _T("ListStates"), strItem, nSort );
00806 
00807         if ( strOrdering.GetLength() == nColumns * 2 &&
00808                  strWidths.GetLength() == nColumns * 4 )
00809         {
00810                 UINT* pOrdering = new UINT[ nColumns ];
00811 
00812                 for ( int nColumn = 0 ; nColumn < nColumns ; nColumn++ )
00813                 {
00814                         _stscanf( strWidths.Mid( nColumn * 4, 4 ), _T("%x"), &pOrdering[ nColumn ] );
00815                         pCtrl->SetColumnWidth( nColumn, pOrdering[ nColumn ] );
00816                         _stscanf( strOrdering.Mid( nColumn * 2, 2 ), _T("%x"), &pOrdering[ nColumn ] );
00817                 }
00818 
00819                 pCtrl->SendMessage( LVM_SETCOLUMNORDERARRAY, nColumns, (LPARAM)pOrdering );
00820                 delete [] pOrdering;
00821                 bSuccess = TRUE;
00822         }
00823 
00824         SetWindowLong( pCtrl->GetSafeHwnd(), GWL_USERDATA, nSort );
00825 
00826         CHeaderCtrl* pHeader = (CHeaderCtrl*)pCtrl->GetWindow( GW_CHILD );
00827         if ( pHeader ) Skin.Translate( pszName, pHeader );
00828 
00829         return bSuccess;
00830 }
00831 
00832 void CSettings::SaveList(LPCTSTR pszName, CListCtrl* pCtrl)
00833 {
00834         CRegistry pRegistry;
00835         LV_COLUMN pColumn;
00836         
00837         pColumn.mask = LVCF_FMT;
00838     int nColumns = 0;
00839         for ( ; pCtrl->GetColumn( nColumns, &pColumn ) ; nColumns++ );
00840         
00841         UINT* pOrdering = new UINT[ nColumns ];
00842         ZeroMemory( pOrdering, nColumns * sizeof(UINT) );
00843         pCtrl->SendMessage( LVM_GETCOLUMNORDERARRAY, nColumns, (LPARAM)pOrdering );
00844         
00845         CString strOrdering, strWidths, strItem;
00846         
00847         for ( int nColumn = 0 ; nColumn < nColumns ; nColumn++ )
00848         {
00849                 strItem.Format( _T("%.2x"), pOrdering[ nColumn ] );
00850                 strOrdering += strItem;
00851                 strItem.Format( _T("%.4x"), pCtrl->GetColumnWidth( nColumn ) );
00852                 strWidths += strItem;
00853         }
00854         
00855         delete [] pOrdering;
00856         
00857         int nSort = GetWindowLong( pCtrl->GetSafeHwnd(), GWL_USERDATA );
00858         
00859         strItem.Format( _T("%s.Ordering"), pszName );
00860         pRegistry.SetString( _T("ListStates"), strItem, strOrdering);
00861         strItem.Format( _T("%s.Widths"), pszName );
00862         pRegistry.SetString( _T("ListStates"), strItem, strWidths);
00863         strItem.Format( _T("%s.Sort"), pszName );
00864         pRegistry.SetInt( _T("ListStates"), strItem, nSort );
00865 }
00866 
00868 // CSettings startup
00869 
00870 BOOL CSettings::CheckStartup()
00871 {
00872         BOOL bStartup;
00873         HKEY hKey;
00874 
00875         if ( RegOpenKeyEx( HKEY_CURRENT_USER,
00876                 _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_QUERY_VALUE, &hKey )
00877                 != ERROR_SUCCESS ) return FALSE;
00878 
00879         bStartup = ( RegQueryValueEx( hKey, _T("Shareaza"), NULL, NULL, NULL, NULL ) == ERROR_SUCCESS );
00880 
00881         RegCloseKey( hKey );
00882 
00883         return bStartup;
00884 }
00885 
00886 void CSettings::SetStartup(BOOL bStartup)
00887 {
00888         HKEY hKey;
00889 
00890         if ( RegOpenKeyEx( HKEY_CURRENT_USER,
00891                 _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hKey )
00892                 != ERROR_SUCCESS ) return;
00893 
00894         if ( bStartup )
00895         {
00896                 CString strCommand;
00897                 TCHAR szPath[128];
00898 
00899                 GetModuleFileName( NULL, szPath, 128 );
00900                 strCommand.Format( _T("\"%s\" -tray"), szPath );
00901 
00902                 RegSetValueEx( hKey, _T("Shareaza"), 0, REG_SZ, (const BYTE*)(LPCTSTR)strCommand,
00903                         ( strCommand.GetLength() + 1 ) * sizeof(TCHAR) );
00904         }
00905         else
00906         {
00907                 RegDeleteValue( hKey, _T("Shareaza") );
00908         }
00909 
00910         RegCloseKey( hKey );
00911 }
00912 
00914 // CSettings configurable user agent (Client Name + Version)
00915 
00916 CString CSettings::SmartAgent()
00917 {
00918         CString strAgent = _T( CLIENT_NAME ); 
00919         strAgent += _T(" ");
00920         strAgent += theApp.m_sVersion;
00921                 
00922         return strAgent;
00923 }
00924 
00926 // CSettings volume
00927 
00928 CString CSettings::SmartVolume(QWORD nVolume, BOOL bKB, BOOL bRateInBits, BOOL bTruncate)
00929 {       //Returns a nicely formatted string displaying a given transfer speed
00930         LPCTSTR pszUnit = _T("B");
00931         CString strVolume;
00932         
00933         if ( bRateInBits )
00934         {
00935                 if ( General.RatesInBytes )
00936                 {
00937                         nVolume /= 8;
00938                         pszUnit = _T("B/s");
00939                 }
00940                 else
00941                 {
00942                         pszUnit = _T("b/s");
00943                 }
00944                 
00945                 if ( General.RatesUnit > 0 )
00946                 {
00947                         if ( bKB ) nVolume *= 1024;
00948                         
00949                         switch ( General.RatesUnit )
00950                         {
00951                         case 1:
00952                                 strVolume.Format( _T("%I64i %s"), nVolume, pszUnit );
00953                                 return theApp.m_bRTL ? _T("\x200E") + strVolume : strVolume;
00954                         case 2:
00955                                 strVolume.Format( _T("%.2lf K%s"), (double)nVolume / 1024, pszUnit );
00956                                 return theApp.m_bRTL ? _T("\x200E") + strVolume : strVolume;
00957                         case 3:
00958                                 strVolume.Format( _T("%.2lf M%s"), (double)nVolume / (1024*1024), pszUnit );
00959                                 return theApp.m_bRTL ? _T("\x200E") + strVolume : strVolume;
00960                         }
00961                         
00962                         if ( bKB ) nVolume /= 1024;
00963                 }
00964         }
00965         
00966         if ( ! bKB )
00967         {
00968                 if ( nVolume < 1024 )
00969                 {
00970                         strVolume.Format( _T("%I64i %s"), nVolume, pszUnit );
00971                         return theApp.m_bRTL ? _T("\x200E") + strVolume : strVolume;
00972                 }
00973                 
00974                 nVolume /= 1024;
00975         }
00976 
00977 
00978         if ( nVolume < 1024 )                                                   // Kilo
00979         {
00980                 strVolume.Format( _T("%I64i K%s"), nVolume, pszUnit );
00981         }
00982         else if ( nVolume < 1024*1024 )                                 // Mega
00983         {
00984                 if ( bTruncate )
00985                         strVolume.Format( _T("%.0lf M%s"), (double)nVolume / 1024, pszUnit );
00986                 else
00987                         strVolume.Format( _T("%.2lf M%s"), (double)nVolume / 1024, pszUnit );
00988         }
00989         else if ( nVolume < 1024*1024*1024 )                    // Giga
00990         {
00991                 if ( bTruncate )
00992                         strVolume.Format( _T("%.0lf G%s"), (double)nVolume / (1024*1024), pszUnit );
00993                 else
00994                         strVolume.Format( _T("%.3lf G%s"), (double)nVolume / (1024*1024), pszUnit );
00995         }
00996         else if ( nVolume < 1099511627776.0f )                  // Tera
00997         {
00998                 if ( bTruncate )
00999                         strVolume.Format( _T("%.0lf T%s"), (double)nVolume / (1024*1024*1024), pszUnit );
01000                 else
01001                         strVolume.Format( _T("%.3lf T%s"), (double)nVolume / (1024*1024*1024), pszUnit );
01002         }
01003         else  if ( nVolume < 1125899906842624.0f )              // Peta
01004         {
01005                 if ( bTruncate )
01006                         strVolume.Format( _T("%.0lf P%s"), (double)nVolume / (1099511627776.0f), pszUnit );
01007                 else
01008                         strVolume.Format( _T("%.3lf P%s"), (double)nVolume / (1099511627776.0f), pszUnit );
01009         }
01010         else                                                                                    // Exa
01011         {
01012                 if ( bTruncate )
01013                         strVolume.Format( _T("%.0lf E%s"), (double)nVolume / (1125899906842624.0f), pszUnit );
01014                 else
01015                         strVolume.Format( _T("%.3lf E%s"), (double)nVolume / (1125899906842624.0f), pszUnit );
01016         }
01017         
01018         return theApp.m_bRTL ? _T("\x200E") + strVolume : strVolume;
01019 }
01020 
01021 QWORD CSettings::ParseVolume(LPCTSTR psz, BOOL bSpeedInBits)
01022 {
01023         double val = 0;
01024 
01025         CString strTmp(psz);
01026         if ( strTmp.Left( 1 ) == _T("\x200E") ) strTmp = strTmp.Mid( 1 );
01027     const TCHAR* psz1 = strTmp;
01028 
01029         if ( _stscanf( psz1 , _T("%lf"), &val ) != 1 ) return 0;
01030 
01031         if ( _tcsstr( psz1, _T("K") ) ) val *= 1024;                                            // Kilo
01032         if ( _tcsstr( psz1, _T("k") ) ) val *= 1024;
01033         
01034         if ( _tcsstr( psz1, _T("M") ) ) val *= 1024*1024;                                       // Mega
01035         if ( _tcsstr( psz1, _T("m") ) ) val *= 1024*1024;
01036         
01037         if ( _tcsstr( psz1, _T("G") ) ) val *= 1024*1024*1024;                          // Giga
01038         if ( _tcsstr( psz1, _T("g") ) ) val *= 1024*1024*1024;
01039         
01040         if ( _tcsstr( psz1, _T("T") ) ) val *= 1099511627776.0f;                        // Tera
01041         if ( _tcsstr( psz1, _T("t") ) ) val *= 1099511627776.0f;
01042 
01043         if ( _tcsstr( psz1, _T("P") ) ) val *= 1125899906842624.0f;                     // Peta
01044         if ( _tcsstr( psz1, _T("p") ) ) val *= 1125899906842624.0f;
01045         
01046         if ( _tcsstr( psz1, _T("E") ) ) val *= 1152921504606846976.0f;          // Exa
01047         if ( _tcsstr( psz1, _T("e") ) ) val *= 1152921504606846976.0f;
01048 
01049         if ( bSpeedInBits )
01050         {
01051                 if ( _tcschr( psz1, 'b' ) )
01052                         return (QWORD)val;
01053                 else if ( _tcschr( psz1, 'B' ) )
01054                         return (QWORD)( val * 8 );
01055                 else
01056                         return 0;
01057         }
01058         else
01059         {
01060                 return (QWORD)val;
01061         }
01062 }
01063 
01065 // CSettings::CheckBandwidth 
01066 
01067 DWORD CSettings::GetOutgoingBandwidth()
01068 {       // This returns the available (Affected by limit) outgoing bandwidth in KB/s
01069         if ( Settings.Bandwidth.Uploads == 0 )
01070                 return ( Settings.Connection.OutSpeed / 8 );
01071 
01072         return ( min( ( Settings.Connection.OutSpeed / 8 ), ( Settings.Bandwidth.Uploads / 1024 ) ) );
01073 }
01074 
01076 // CSettings::Item construction and operations
01077 
01078 CSettings::Item::Item(LPCTSTR pszName, DWORD* pDword, DOUBLE* pFloat, CString* pString)
01079 {
01080         m_sName         = pszName;
01081         m_pDword        = pDword;
01082         m_pFloat        = pFloat;
01083         m_pString       = pString;
01084 }
01085 
01086 void CSettings::Item::Load()
01087 {
01088         CRegistry pRegistry;
01089         
01090         int nPos = m_sName.Find( '.' );
01091         if ( nPos < 0 ) return;
01092 
01093         if ( m_pDword )
01094         {
01095                 *m_pDword = pRegistry.GetDword( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), *m_pDword );
01096         }
01097         else if ( m_pFloat )
01098         {
01099                 *m_pFloat = pRegistry.GetFloat( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), *m_pFloat );
01100         }
01101         else
01102         {
01103                 *m_pString = pRegistry.GetString( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), *m_pString );
01104         }
01105 
01106 }
01107 
01108 void CSettings::Item::Save()
01109 {
01110         CRegistry pRegistry;
01111         
01112         int nPos = m_sName.Find( '.' );
01113         if ( nPos < 0 ) return;
01114 
01115         if ( m_pDword )
01116         {
01117                 pRegistry.SetInt( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), *m_pDword );
01118         }
01119         else if ( m_pFloat )
01120         {
01121                 CString str;
01122                 str.Format( _T("%e"), *m_pFloat );
01123                 pRegistry.SetString( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), str );
01124         }
01125         else
01126         {
01127                 pRegistry.SetString( m_sName.Left( nPos ), m_sName.Mid( nPos + 1 ), *m_pString );
01128         }
01129 }

Generated on Thu Dec 15 10:39:48 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2