XDCC-Fetch 1.386 → 1.409

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,10 +24,9 @@
24
24
 
25
25
  DCC_Resume_Verification = Struct.new("DCC_Resume_Verification",
26
26
  :verified,
27
- :bytes_mine,
28
- :md5_mine,
29
- :bytes_their,
30
- :md5_their)
27
+ :bytes_total,
28
+ :bytes_mine,
29
+ :bytes_their)
31
30
 
32
31
  DCC_File_Info = Struct.new("DCC_File_Info",
33
32
  :status, # Status of DCC
@@ -86,7 +85,7 @@ class DCC_File
86
85
  "",
87
86
  nil,
88
87
  nil,
89
- DCC_Resume_Verification.new(false, 0, nil, 0, nil),
88
+ DCC_Resume_Verification.new(false, 0, "", ""),
90
89
  false,
91
90
  ON_DCC_ERROR,
92
91
  "",
@@ -138,14 +137,22 @@ class DCC_File
138
137
  end
139
138
  # As of now, no md5 checksum will be calculated for resumed packs in order to not
140
139
  # slow down everything only due to md5 checksum calculation for the received data
141
- @info.bytes_received = File.size(@info.joined_filename)
140
+ local_filesize = File.size(@info.joined_filename)
141
+
142
142
  # Initialize verification
143
- @info.verification.verified = false
144
- @info.verification.bytes_mine = (@info.bytes_received > $cfg.network.dcc.verification_bytes) ? $cfg.network.dcc.verification_bytes : @info.bytes_received
143
+ if $cfg.network.dcc.enable_verification
144
+ @info.verification.verified = false
145
+ @info.verification.bytes_total = (local_filesize > $cfg.network.dcc.verification_bytes) ? $cfg.network.dcc.verification_bytes : local_filesize
146
+ else
147
+ # Verification disabled
148
+ @info.verification.verified = true
149
+ @info.verification.bytes_total = 0
150
+ end
151
+ @info.bytes_received = local_filesize - @info.verification.bytes_total
145
152
  if @info.bytes_received < @info.bytes_total
146
153
  # Ask for DCC RESUME
147
154
  @info.irc_user.irc_server.connect_to_events(IRC_Server::ON_USER_MESSAGE, self)
148
- @info.irc_user.send("\001DCC RESUME #{@info.filename} #{@info.address.port} #{@info.bytes_received - @info.verification.bytes_mine}\001")
155
+ @info.irc_user.send("\001DCC RESUME #{@info.filename} #{@info.address.port} #{@info.bytes_received}\001")
149
156
  elsif @info.bytes_received == @info.bytes_total
150
157
  # Pack already received. At least filesize tells us so. We therefore download a single byte from bot in
151
158
  # order to terminate the connection fast and make it available for other packs.
@@ -206,10 +213,8 @@ class DCC_File
206
213
  return
207
214
  end
208
215
  if !@info.verification.verified
209
- @info.file.seek(-@info.verification.bytes_mine, IO::SEEK_END)
210
- @info.verification.md5_mine = Digest::MD5.new
211
- @info.verification.md5_their = Digest::MD5.new
212
- @info.verification.md5_mine << @info.file.read
216
+ @info.file.seek(-@info.verification.bytes_total, IO::SEEK_END)
217
+ @info.verification.bytes_mine << @info.file.read
213
218
  else
214
219
  @info.file.seek(0, IO::SEEK_END)
215
220
  end
@@ -232,6 +237,8 @@ class DCC_File
232
237
  end
233
238
 
234
239
  when TCP_Connection::ON_CLOSED
240
+ @tcp_con.close if @tcp_con.connected?
241
+ @info.file.close if @info.file && !@info.file.closed?
235
242
  if @info.bytes_received != @info.bytes_total
236
243
  if !@info.status == ON_DCC_ERROR
237
244
  # No other code has yet triggered a download failed event
@@ -239,7 +246,6 @@ class DCC_File
239
246
  self.fire_event(ON_DCC_ERROR, $cfg.text.network.xdcc.err_con_closed)
240
247
  end
241
248
  else
242
- @tcp_con.close if @tcp_con.connected?
243
249
  @info.status = ON_DCC_COMPLETED
244
250
  self.fire_event(ON_DCC_COMPLETED, @info.md5)
245
251
  end
@@ -247,6 +253,8 @@ class DCC_File
247
253
  when TCP_Connection::ON_ERROR
248
254
  # See if some other code has already triggered a download failed
249
255
  if @info.status != ON_DCC_ERROR && @info.status != ON_DCC_COMPLETED
256
+ @tcp_con.close if @tcp_con.connected?
257
+ @info.file.close if @info.file && !@info.file.closed?
250
258
  @info.status = ON_DCC_ERROR
251
259
  self.fire_event(ON_DCC_ERROR, eventargs[0])
252
260
  end
@@ -256,32 +264,28 @@ class DCC_File
256
264
  return
257
265
  end
258
266
 
259
- # Verify bytes if necessary
260
- if !@info.verification.verified
261
- self.add_verification_bytes(eventargs[0])
262
- if @info.verification.bytes_mine == @info.verification.bytes_their
263
- # Ready for md5 comparison
264
- if @info.verification.md5_mine.hexdigest != @info.verification.md5_their.hexdigest
265
- @info.status = ON_DCC_ERROR
266
- self.fire_event(ON_DCC_ERROR, $cfg.text.network.dcc.err_verification)
267
- @tcp_con.close
268
- @info.file.close
269
- return
270
- else
271
- @info.verification.verified = true
272
- # Write remaining bytes to file
273
- end
274
- else
275
- # All bytes have been eat up by verification
276
- return
277
- end
278
- end
279
-
280
267
  # Increment download count after possible verification, as @info.bytes_received
281
268
  # starts counting at local filesize.
282
269
  @info.bytes_received += eventargs[0].length
283
270
  # Ack data, as 4 byte integer big-endian network byte order
284
271
  @tcp_con.send([@info.bytes_received].pack('N'))
272
+
273
+ # Verify bytes if necessary
274
+ if !@info.verification.verified
275
+ if !self.verify_bytes(eventargs[0])
276
+ @info.status = ON_DCC_ERROR
277
+ self.fire_event(ON_DCC_ERROR, $cfg.text.network.dcc.err_verification)
278
+ @tcp_con.close
279
+ @info.file.close
280
+ return
281
+ end
282
+ elsif @info.verification.bytes_mine.length == @info.verification.bytes_their.length
283
+ @info.verification.verified = true
284
+ # Write remaining bytes to file
285
+ else
286
+ # All bytes have been eaten up by verification
287
+ return
288
+ end
285
289
 
286
290
  # Write to file
287
291
  @info.file.syswrite(eventargs[0])
@@ -308,16 +312,22 @@ class DCC_File
308
312
  end
309
313
  end
310
314
 
311
- def add_verification_bytes(bytes)
312
- return if @info.verification.bytes_their == @info.verification.bytes_mine
313
- their_length = bytes.length
314
- if (@info.verification.bytes_their + their_length <= @info.verification.bytes_mine)
315
- @info.verification.bytes_their += their_length
316
- @info.verification.md5_their << bytes.slice!(0..-1)
315
+ def verify_bytes(bytes)
316
+ my_length = @info.verification.bytes_mine.length
317
+ their_length = @info.verification.bytes_their.length
318
+ return true if my_length == their_length
319
+ startpos = their_length
320
+ endpos = 0
321
+ if their_length + bytes.length < my_length
322
+ # All bytes are required for verification
323
+ endpos = their_length + bytes.length - 1
324
+ @info.verification.bytes_their << bytes.slice!(0..-1)
317
325
  else
318
- req_length = @info.verification.bytes_mine - @info.verification.bytes_their
319
- @info.verification.bytes_their += req_length
320
- @info.verification.md5_their << bytes.slice!(0..req_length - 1)
326
+ # Bytes are partly required for verification
327
+ req_bytes = bytes.slice!(0..(my_length - their_length - 1))
328
+ endpos = their_length + req_bytes.length - 1
329
+ @info.verification.bytes_their << req_bytes
321
330
  end
331
+ return @info.verification.bytes_their[startpos..endpos] == @info.verification.bytes_mine[startpos..endpos]
322
332
  end
323
333
  end
@@ -24,7 +24,8 @@
24
24
 
25
25
 
26
26
  require 'socket'
27
- require 'resolv-replace'
27
+ # Disable ruby's own resolver, seemed to cause serious troubles on some windowses.
28
+ #require 'resolv-replace'
28
29
  require 'src/Utilities/Events.rb'
29
30
  require 'timeout'
30
31
 
@@ -69,6 +70,8 @@ class TCP_Connection
69
70
  # That way, the the main thread is not blocked if connection cannot be
70
71
  # established
71
72
  connect_thread = Thread.new do
73
+ # Lower priority of connect thread. This may help higher level applications to increase there response time
74
+ Thread.current.priority = $cfg.network.tcp.connect_thread_priority
72
75
  if @address && @port
73
76
  begin
74
77
  timeout($cfg.network.tcp.connect_timeout) {
@@ -83,13 +86,13 @@ class TCP_Connection
83
86
  end
84
87
  self.close
85
88
  self.fire_event(ON_CLOSED)
86
- rescue IOError, Errno::ECONNRESET, Errno::ENOTSOCK, SocketError => err
89
+ rescue IOError, SystemCallError, SocketError => err
87
90
  self.fire_event(ON_ERROR, err.to_s)
88
91
  end
89
92
  end
90
93
  rescue TimeoutError => err
91
94
  self.fire_event(ON_ERROR, $cfg.text.network.tcp.err_con_timeout)
92
- rescue IOError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError => err
95
+ rescue IOError, SystemCallError, SocketError => err
93
96
  self.close
94
97
  self.fire_event(ON_ERROR, err.to_s)
95
98
  end
@@ -101,8 +104,6 @@ class TCP_Connection
101
104
  # Already connected
102
105
  self.fire_event(ON_ERROR, $cfg.text.network.tcp.err_con_active)
103
106
  end
104
- # Lower priority of connect thread. This may help higher level applications to increase there response time
105
- connect_thread.priority = $cfg.network.tcp.connect_thread_priority
106
107
  end
107
108
 
108
109
  # Send data to socket
@@ -350,7 +350,11 @@ class XDCC_Download_Handler
350
350
  elsif status = $cfg.network.xdcc.md5_regexp.match(message)
351
351
  handle_delayed_md5(status[1])
352
352
  elsif status = $cfg.network.xdcc.punish_slowness_regexp.match(message)
353
+ @mutex.synchronize do
354
+ @current_pack_status = ON_DOWNLOAD_FAILED
355
+ end
353
356
  self.fire_event(ON_DOWNLOAD_FAILED, @current_pack, $cfg.text.network.xdcc.err_punish_slowness)
357
+ @dcc_con.close
354
358
  self.next_pack(5)
355
359
  end
356
360
 
@@ -362,7 +366,7 @@ class XDCC_Download_Handler
362
366
  self.fire_event(ON_DOWNLOAD_STARTED, @current_pack)
363
367
 
364
368
  when DCC_File::ON_DCC_ERROR
365
- @mutex.synchronize do
369
+ @mutex.synchronize do
366
370
  @current_pack_status = ON_DOWNLOAD_FAILED
367
371
  end
368
372
  self.fire_event(ON_DOWNLOAD_FAILED, @current_pack, eventargs[0])
@@ -21,7 +21,7 @@ if __FILE__ == $0
21
21
  end
22
22
  end
23
23
  # english is the reference language
24
- @reference_language = $cfg.text.en
24
+ @reference_language = $cfg.translations.en
25
25
  end
26
26
 
27
27
  def self.usage
@@ -41,10 +41,10 @@ if __FILE__ == $0
41
41
  end
42
42
 
43
43
  def check
44
- $cfg.text.attrs.each do |lang_name|
45
- next if $cfg.text[lang_name] == @reference_language
46
- @attr_stack = [ "$cfg.text", lang_name]
47
- check_attrs(@reference_language, $cfg.text[lang_name])
44
+ $cfg.translations.attrs.each do |lang_name|
45
+ next if $cfg.translations[lang_name] == @reference_language
46
+ @attr_stack = [ "$cfg.translations", lang_name]
47
+ check_attrs(@reference_language, $cfg.translations[lang_name])
48
48
  end
49
49
  # print status
50
50
  print_status(@missing, "missing translation items:")
@@ -24,7 +24,7 @@
24
24
 
25
25
  # Language definition #################################
26
26
 
27
- lang = $cfg.text.de
27
+ lang = $cfg.translations.de
28
28
  lang.language_name = "German"
29
29
 
30
30
  lang.about = "&�ber\t\tZeigt �ber-Dialog"
@@ -110,6 +110,8 @@ lang.speed = "Geschwindigkeit"
110
110
  lang.download_finished_box = "Fertig Heruntergeladen"
111
111
 
112
112
  lang.show_warning = "&Fehler Zeigen"
113
+ lang.language = "&Sprache"
114
+ lang.options = "Optionen"
113
115
 
114
116
 
115
117
  # Network messages
@@ -24,7 +24,7 @@
24
24
 
25
25
  # Language definition #################################
26
26
 
27
- lang = $cfg.text.en
27
+ lang = $cfg.translations.en
28
28
  lang.language_name = "English"
29
29
 
30
30
  lang.about = "&About\t\tShows an about dialog"
@@ -118,6 +118,10 @@ lang.credits = "Credits"
118
118
  lang.download_finished_box = "Download Finished"
119
119
 
120
120
  lang.show_warning = "&Show Error"
121
+ lang.options = "&Options"
122
+ lang.language = "&Language"
123
+
124
+ lang.you_have_to_restart = "Restart XDCC-Fetch to apply changes"
121
125
 
122
126
  # Network messages
123
127
  lang.network.ip.err_notroutable_ip = "Not routable ip address given"
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2004, 2005 Christoph Heindl and Martin Ankerl
2
+ # All rights reserved.
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without modification,
5
+ # are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice, this list
8
+ # of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright notice, this list
10
+ # of conditions and the following disclaimer in the documentation and/or other materials
11
+ # provided with the distribution.
12
+ # * Neither the name of Christoph Heindl and Martin Ankerl nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software without specific
14
+ # prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17
+ # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22
+ # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
23
+ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
25
+ # Language definition #################################
26
+
27
+ lang = $cfg.translations.pl
28
+ lang.language_name = "Polish"
29
+
30
+ lang.about = "&O programie\t\tPokazuje okno dialogowe O programie"
31
+ lang.help = "&Pomoc"
32
+ lang.add_server = "&Dodaj serwer\tCtrl-A\tDodaje i ��czy si� z serwerem IRC"
33
+ lang.remove_server = "Usu�\t\tRoz��cza i usuwa serwer IRC"
34
+ lang.add_channel = "Dodaj kana�\t\tDodaje (wchodzi) kana�"
35
+ lang.add_channel_dialog = "Dodaj kana�"
36
+ lang.remove_channel = "Usu�\t\tUsuwa (opuszcza) kana�"
37
+ lang.specify_server = "Okre�l serwer"
38
+
39
+ lang.server = "Serwer"
40
+ lang.port = "Port"
41
+ lang.nickname = "Nick"
42
+ lang.password = "Has�o"
43
+ lang.channel = "Kana�"
44
+
45
+ lang.disconnect = "&Roz��cz"
46
+ lang.connect = "&Po��cz"
47
+
48
+
49
+ lang.file = "&Plik"
50
+ lang.quit = "&Wyj�cie\tCtrl-X\tZamyka program i wszystkie aktywne po��czenia"
51
+
52
+ lang.speed_widget_init = "0.0 kb\tPokazuje ca�kowit� pr�dko�� pobierania w kilobajtach\tPokazuje ca�kowit� pr�dko�� pobierania w kilobajtach"
53
+
54
+ lang.enter_ip_or_domain = "Wpisz IP lub domen�"
55
+ lang.the_servers_port = "Port serwera"
56
+
57
+ lang.channel_name = "Nazwa kana�u"
58
+ lang.connections = "Po��czenia\tPrawoklik na zasadniczym obszarze\naby doda� serwery IRC oraz kana�y\tPrawoklik na zasadniczym obszarze aby doda� serwery IRC oraz kana�y"
59
+ lang.search = "Szukaj\tWpisz swoje zapytanie w pole po prawej\tWpisz swoje zapytanie w pole po prawej"
60
+
61
+ lang.free_slots = "\tPoka�/ukryj pakiety gdzie\nbot ma wolne sloty\tPokazuje/ukrywa pakiety gdzie bot ma wolne sloty"
62
+ lang.slots_unknown = "\tPoka�/ukryj pakiety gdzie\nilo�� slot�w jest nieznana\tPokazuje/ukrywa pakiety gdzie ilo�� slot�w jest nieznana"
63
+ lang.no_free_slots = "\tPoka�/ukryj pakiety gdzie\nbot nie posiada wolnych slot�w\tPokazuje/ukrywa pakiety gdzie bot nie posiada wolnych slot�w"
64
+
65
+ lang.what_do_you_want_to_fetch_today = "Co chcesz dzisiaj �ci�gn��?"
66
+
67
+ lang.bot = "Bot"
68
+ lang.name = "Nazwa"
69
+ lang.size = "Rozmiar"
70
+
71
+ lang.active = "Aktywne\tPokazuje aktywne pobierania\tPokazuje aktywne pobierania"
72
+ lang.completed = "Zako�czone\tPokazuje zako�czone pobierania\tPokazuje zako�czone pobierania"
73
+ lang.error = "B��d\tPokazuje przerwane pobierania\tPokazuje przerwane pobierania"
74
+
75
+ lang.download = "&Pobierz\t\tPobierz tego packa"
76
+ lang.status = "Status"
77
+ lang.target_directory = "Katalog pobiera�"
78
+ lang.clear_list = "&Czy�� list�"
79
+
80
+ lang.download_waiting = "Oczekiwanie"
81
+ lang.download_requesting = "��danie"
82
+ lang.download_timeout = "Timeout"
83
+ lang.download_cancelling = "Anulowanie"
84
+ lang.download_started = "Pobieranie"
85
+ lang.download_finished = "Uko�czone"
86
+ lang.download_failed = "Nieudane"
87
+ lang.queue_remote = "Zdalnie zakolejkowane: "
88
+ lang.queue_local = "Lokalnie zakolejkowane: "
89
+ lang.speed = "Szybko��"
90
+
91
+ lang.version = "Wersja"
92
+ lang.revision = "Podwersja"
93
+ lang.credits = "Developerzy"
94
+ lang.thanks = "Specjalne podzi�kowania dla"
95
+
96
+
97
+ # "x of x packs"
98
+ lang.of = "/"
99
+ lang.packs = ""
100
+ lang.status_label_tooltip = "\tPokazuje ilo�� widocznych\npack�w / ca�kowit� ilo�� pack�w\tPokazuje ilo�� widocznych pack�w / ca�kowit� ilo�� pack�w"
101
+
102
+ lang.cancel = "&Anuluj\t\tAnuluje pobieranie"
103
+ lang.submit = "&Wy�lij"
104
+
105
+ lang.md5.disabled = "nieznane"
106
+ lang.md5.unavailable = "nieznane"
107
+ lang.md5.ok = "ok"
108
+ lang.md5.failed = "z�e"
109
+
110
+ lang.checksum = "Suma kontrolna"
111
+
112
+ lang.speed = "Szybko��"
113
+
114
+ lang.version = "Wersja"
115
+ lang.revision = "Podwersja"
116
+ lang.credits = "Podzi�kowania"
117
+
118
+ lang.download_finished_box = "Pobieranie zako�czone"
119
+
120
+ lang.show_warning = "&Poka� b��d"
121
+
122
+ # Network messages
123
+ lang.network.ip.err_notroutable_ip = "Nie wpisano rutowalnego adresu ip"
124
+ lang.network.tcp.err_invalid_address = "Nieprawid�owe info o adresie/porcie TCP"
125
+ lang.network.tcp.err_con_closed = "Po��czenie zosta�o zamkni�te"
126
+ lang.network.tcp.err_con_active = "Po��czenie jest aktywne"
127
+ lang.network.tcp.err_con_timeout = "Timeout podczas pr�by po��czenia"
128
+ lang.network.tcp.err_con_no_remote = "Nie zosta� okre�lony adres i/lub port"
129
+ lang.network.dcc.err_dir_notexist = "Nie istnieje katalog docelowy"
130
+ lang.network.dcc.err_file_permission = "Nie mo�na zapisa� do pliku"
131
+ lang.network.dcc.err_filesize_differ = "Rozmiar pliku wygl�da na inny"
132
+ lang.network.dcc.err_verification = "Nieudana weryfikacja pliku"
133
+ lang.network.xdcc.err_punish_slowness = "Zbyt ma�a pr�dko�c pobierania od bota"
134
+ lang.network.xdcc.err_pack_already_requested = "Ju� za��dano tego packa"
135
+ lang.network.xdcc.err_max_packs_requested = "Max ilo�� pack�w ��danych od bota"
136
+ lang.network.xdcc.err_bot_left = "Bot opu�ci� IRC"
137
+ lang.network.xdcc.err_server_disconnect = "Utracono po��czenie z serwerem IRC"
138
+ lang.network.xdcc.err_con_closed = "Po��czenie zosta�o zdalnie zamkni�te"
139
+ lang.network.xdcc.err_no_answer = "Brak odpowiedzi XDCC"
140
+ lang.network.xdcc.err_ip_address_conversion = "Nie mo�na okre�li� adresu IP"
141
+ lang.network.xdcc.cancel_download_default = "U�ytkownik anulowa� pobieranie"
142
+
143
+
144
+ lang.message.connection_error_title = "B��d po��czenia"
145
+ lang.message.connection_error = "Nieudane po��czenie z serwerem IRC"
@@ -74,7 +74,7 @@ class Configuration
74
74
 
75
75
  def set_language(lang_id)
76
76
  @lang.re_open
77
- copy(@lang[lang_id], @lang)
77
+ copy(@whole_config.translations[lang_id], @lang)
78
78
  @lang.close
79
79
  end
80
80