rwdtorrent 0.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/Readme.txt +146 -0
  2. data/bin/rwdtorrent +19 -0
  3. data/code/01rwdcore/01rwdcore.rb +22 -0
  4. data/code/01rwdcore/02helptexthashbegin.rb +4 -0
  5. data/code/01rwdcore/03helptexthash.rb +31 -0
  6. data/code/01rwdcore/04helptextend.rb +6 -0
  7. data/code/01rwdcore/openhelpwindow.rb +31 -0
  8. data/code/01rwdcore/returntomain.rb +10 -0
  9. data/code/01rwdcore/rwdtinkerversion.rb +15 -0
  10. data/code/01rwdcore/rwdwindowreturn.rb +11 -0
  11. data/code/01rwdcore/test_cases.rb +126 -0
  12. data/code/01rwdcore/test_harness.rb +15 -0
  13. data/code/01rwdcore/uploadreturns.rb +62 -0
  14. data/code/superant.com.rwdtinkerbackwindow/controlclient.rb +99 -0
  15. data/code/superant.com.rwdtinkerbackwindow/diagnostictab.rb +25 -0
  16. data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +61 -0
  17. data/code/superant.com.rwdtinkerbackwindow/installapplet.rb +24 -0
  18. data/code/superant.com.rwdtinkerbackwindow/installgemapplet.rb +20 -0
  19. data/code/superant.com.rwdtinkerbackwindow/installremotegem.rb +19 -0
  20. data/code/superant.com.rwdtinkerbackwindow/listgemdirs.rb +12 -0
  21. data/code/superant.com.rwdtinkerbackwindow/listgemzips.rb +54 -0
  22. data/code/superant.com.rwdtinkerbackwindow/listinstalledfiles.rb +11 -0
  23. data/code/superant.com.rwdtinkerbackwindow/listzips.rb +31 -0
  24. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationrecord.rb +32 -0
  25. data/code/superant.com.rwdtinkerbackwindow/loadconfigurationvariables.rb +13 -0
  26. data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
  27. data/code/superant.com.rwdtinkerbackwindow/openappletname.rb +18 -0
  28. data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +42 -0
  29. data/code/superant.com.rwdtinkerbackwindow/remotegemlist.rb +24 -0
  30. data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +32 -0
  31. data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +12 -0
  32. data/code/superant.com.rwdtinkerbackwindow/rwdtinkerwin2version.rb +14 -0
  33. data/code/superant.com.rwdtinkerbackwindow/saveconfigurationrecord.rb +18 -0
  34. data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +21 -0
  35. data/code/superant.com.rwdtinkerbackwindow/viewgemappletcontents.rb +21 -0
  36. data/code/superant.com.rwdtorrent/helptesthashrwdtorrent.rb +55 -0
  37. data/code/superant.com.rwdtorrent/listnamerecord.rb +15 -0
  38. data/code/superant.com.rwdtorrent/loadconfigurationrecord.rb +36 -0
  39. data/code/superant.com.rwdtorrent/loadconfigurationvariables.rb +13 -0
  40. data/code/superant.com.rwdtorrent/openhelpwindowtorrent.rb +32 -0
  41. data/code/superant.com.rwdtorrent/returntomain.rb +10 -0
  42. data/code/superant.com.rwdtorrent/runtorrentwindow.rb +57 -0
  43. data/code/superant.com.rwdtorrent/rwdtorrenthelpabout.rb +14 -0
  44. data/code/superant.com.rwdtorrent/saveconfigurationrecord.rb +18 -0
  45. data/code/superant.com.rwdtorrent/stoptorrentdownload.rb +12 -0
  46. data/code/superant.com.rwdtorrent/viewtorrentlist.rb +20 -0
  47. data/code/superant.com.rwdtorrent/viewtorrentmetafile.rb +36 -0
  48. data/code/zz0applicationend/zz0end.rb +4 -0
  49. data/configuration/language.dist +7 -0
  50. data/configuration/rwdapplicationidentity.dist +3 -0
  51. data/configuration/rwdtinker.dist +15 -0
  52. data/configuration/rwdtorrent.dist +11 -0
  53. data/configuration/tinkerwin2variables.dist +17 -0
  54. data/downloads/nodownloads.txt +1 -0
  55. data/ev/browser.rb +109 -0
  56. data/ev/ftools.rb +170 -0
  57. data/ev/net.rb +750 -0
  58. data/ev/ruby.rb +819 -0
  59. data/ev/rwd.rb +1849 -0
  60. data/ev/sgml.rb +236 -0
  61. data/ev/thread.rb +63 -0
  62. data/ev/tree.rb +343 -0
  63. data/ev/xml.rb +4 -0
  64. data/extras/aversa.rb +261 -0
  65. data/extras/rconftool.rb +380 -0
  66. data/extras/rubytorrent.rb +94 -0
  67. data/extras/rubytorrent/bencoding.rb +174 -0
  68. data/extras/rubytorrent/controller.rb +610 -0
  69. data/extras/rubytorrent/message.rb +128 -0
  70. data/extras/rubytorrent/metainfo.rb +214 -0
  71. data/extras/rubytorrent/package.rb +600 -0
  72. data/extras/rubytorrent/peer.rb +536 -0
  73. data/extras/rubytorrent/server.rb +166 -0
  74. data/extras/rubytorrent/tracker.rb +225 -0
  75. data/extras/rubytorrent/typedstruct.rb +132 -0
  76. data/extras/rubytorrent/util.rb +186 -0
  77. data/extras/zip/ioextras.rb +114 -0
  78. data/extras/zip/stdrubyext.rb +111 -0
  79. data/extras/zip/tempfile_bugfixed.rb +195 -0
  80. data/extras/zip/zip.rb +1377 -0
  81. data/extras/zip/zipfilesystem.rb +558 -0
  82. data/extras/zip/ziprequire.rb +61 -0
  83. data/gui/00coreguibegin/applicationguitop.rwd +4 -0
  84. data/gui/frontwindow0/10viewnote.rwd +32 -0
  85. data/gui/frontwindow0/30viewtorrent.rwd +13 -0
  86. data/gui/frontwindow0/40rwdtorrentrefresh.rwd +28 -0
  87. data/gui/frontwindow0/67viewconfiguration.rwd +38 -0
  88. data/gui/frontwindowselectionbegin/selectiontabbegin/selectiontabbegin.rwd +16 -0
  89. data/gui/frontwindowselections/superant.com.rwdtinkerwin2selectiontab/rwdwin2selectiontab.rwd +12 -0
  90. data/gui/frontwindowselectionzend/viewselectionzend/viewselectionend.rwd +3 -0
  91. data/gui/frontwindowtdocumentbegin/superant.com.documentsbegin/tt0documentbegin.rwd +6 -0
  92. data/gui/frontwindowtdocuments/superant.com.documents/uu5documents.rwd +15 -0
  93. data/gui/frontwindowtdocuments/superant.com.tinkerwin2documents/uu5documents.rwd +6 -0
  94. data/gui/frontwindowtdocuments/superant.com.torrentdocument/doctorrent.rwd +6 -0
  95. data/gui/frontwindowtdocumentzend/superant.com.documentsend/ww0documentend.rwd +12 -0
  96. data/gui/frontwindowz1end/frontwindowend/xx0rwdfirsttab.rwd +6 -0
  97. data/gui/helpaboutbegin/superant.com.helpaboutbegin/ya0helpscreenstart.rwd +3 -0
  98. data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/1appname.rwd +4 -0
  99. data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/3copyright.rwd +3 -0
  100. data/gui/helpaboutinstalled/superant.com.tinkerhelpabout/5version.rwd +10 -0
  101. data/gui/helpaboutinstalled/superant.com.torrenthelpabout/1appname.rwd +4 -0
  102. data/gui/helpaboutinstalled/superant.com.torrenthelpabout/3copyright.rwd +3 -0
  103. data/gui/helpaboutinstalled/superant.com.torrenthelpabout/5version.rwd +9 -0
  104. data/gui/helpaboutzend/superant.com.helpaboutend/helpscreenend.rwd +3 -0
  105. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/1appname.rwd +5 -0
  106. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/40rwdlistzips.rwd +42 -0
  107. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/45installremotezip.rwd +44 -0
  108. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +44 -0
  109. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +38 -0
  110. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/70rwddiagnostics.rwd +29 -0
  111. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/75rwdcontrol.rwd +33 -0
  112. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/80tab1.rwd +11 -0
  113. data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/9backend.rwd +6 -0
  114. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +31 -0
  115. data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/9end.rwd +4 -0
  116. data/gui/tinkerbackwindows/superant.com.torrentdisplay/torrentdisplaywindow.rwd +31 -0
  117. data/gui/tinkerbackwindows/superant.com.versionwindow/1appname.rwd +19 -0
  118. data/gui/zzcoreguiend/tinkerapplicationguiend/yy9rwdend.rwd +4 -0
  119. data/init.rb +277 -0
  120. data/installed/rwdviewlogo-0.4.inf +4 -0
  121. data/lang/en/rwdcore/languagefile.rb +16 -0
  122. data/lang/es/rwdcore/languagefile-es.rb +14 -0
  123. data/lang/jp/rwdcore/languagefile.rb +9 -0
  124. data/lang/nl/rwdcore/languagefile.rb +19 -0
  125. data/lib/temp.rb +1 -0
  126. data/rwd_files/HowTo_Tinker.txt +405 -0
  127. data/rwd_files/HowTo_TinkerWin2.txt +202 -0
  128. data/rwd_files/HowTo_Torrent.txt +146 -0
  129. data/rwd_files/Readme.txt +57 -0
  130. data/rwd_files/favicon.ico +0 -0
  131. data/rwd_files/rdoc-style.css +175 -0
  132. data/rwd_files/rwdapplications.html +54 -0
  133. data/rwd_files/rwdindex.html +6 -0
  134. data/rwd_files/tinker.png +0 -0
  135. data/rwdconfig.dist +10 -0
  136. data/tests/checkdepends.sh +4 -0
  137. data/tests/cleancnf.sh +5 -0
  138. data/tests/makedist.rb +44 -0
  139. data/tests/rdep.rb +354 -0
  140. data/tests/rwdtinkertestEN.rb +163 -0
  141. data/tests/test.result +32 -0
  142. data/tests/totranslate.lang +93 -0
  143. data/torrentfiles/freeculture-audiobook.zip.torrent +0 -0
  144. data/torrentfiles/freeculture.zip.torrent +0 -0
  145. data/zips/rwdahelloworld-0.5.zip +0 -0
  146. metadata +199 -0
@@ -0,0 +1,32 @@
1
+ # this code is to call the help window
2
+ def runhelpwindowrwdtorrent
3
+
4
+ $help_topic = "rwdtorrent_generalhelp"
5
+
6
+ if @rwd_tab == "rwdtorrentrefresh"
7
+ $help_topic = "torrentrefresh_help"
8
+ end
9
+
10
+ if @rwd_tab == "superantcomtorrenttab"
11
+ $help_topic = "torrent_help"
12
+ end
13
 
14
+
15
+ if @rwd_tab == "Rwdtorrentsize"
16
+ $help_topic = "torrentsize_help"
17
+ end
18
+
19
+ if @rwd_tab == "viewrwdtorrentconfiguration"
20
+ $help_topic = "rwdtorrent_configuration"
21
+ end
22
+ $helptopicsarray = $helptopicsarray | ["torrent_help","torrentsize_help","rwdtorrent_generalhelp","rwdtorrent_configuration"]
23
+
24
+
25
+
26
+ if @rwd_window != "rwdtinkerhelpwindow"
27
+ $previouswindow = @rwd_window
28
+ $previoustab = @rwd_tab
29
+ end
30
+ runhelpwindow
31
+ end
32
+
33
+
@@ -0,0 +1,10 @@
1
+ # Application rwdtinker orginally (c) 2004 Steven Gibson under GPL.
2
+ #
3
+ # For more information about see http://www.rubyforge.net/projects/rwdapplications
4
+
5
+ # call the window
6
+ def returntomainx
7
+ @rwd_window = "main"
8
+ @rwd_tab = "superantcomtorrenttab"
9
+ end
10
+
@@ -0,0 +1,57 @@
1
+ def runtorrentwindow
2
+ $torrenttodownload = $progdir + "/" + $rwdtorrentfilesdir + "/" + @a_viewtorrent + ".torrent"
3
+ rwdtorrentwindowtwo
4
+ end
5
+
6
+ def runtorrentwindowhttp
7
+ $torrenttodownload = @a_viewtorrenthttp
8
+ rwdtorrentwindowtwo
9
+ end
10
+
11
+ $temptorrentnumber = 0
12
+
13
+ def runtorrentthread
14
+ $torrenttimestart = Time.now
15
+ Dir.chdir($rwdtorrentdownloads)
16
+
17
+ $bt = RubyTorrent::BitTorrent.new("#{$torrenttodownload}")
18
+ $torrentpid = fork do
19
+ puts "\nIn child, pid = #$$ \n"
20
+ thread = Thread.new do
21
+ #while true
22
+ puts $bt.percent_completed
23
+
24
+
25
+ #end
26
+ end
27
+ $bt.on_event(self, :complete) { thread.kill }
28
+ thread.join
29
+ end
30
+ end
31
+
32
+ def rwdtorrentwindowtwo
33
+ require 'extras/rubytorrent'
34
+
35
+ @rwd_call_after_back << "rwdtorrentwindowtwo"
36
+ #if @rwd_tab== "rwdtorrentrefresh"
37
+ @rwd_window = "torrentdisplaywindowtwo"
38
+ # end
39
+ if $temptorrentnumber == 0
40
+ runtorrentthread
41
+ $temptorrentnumber =1
42
+ end
43
+ Dir.chdir($progdir)
44
+ @torrentdisplayvariable = $bt.percent_completed.to_s
45
+ @torrentstarttime = $torrenttimestart
46
+ @torrentcurrenttime = Time.now.to_s
47
+
48
+ commandtext = TorrentListCmd + $rwdtorrentdownloads + "/" + @a_viewtorrent.to_s + "*"
49
+
50
+ begin # exception trapped block
51
+ @torrentcurrentsize =`#{commandtext}`
52
+
53
+ rescue SystemCallError, StandardError
54
+ $stderr.print "system call error: " + $!
55
+ end # exception rescue
56
+
57
+ end
@@ -0,0 +1,14 @@
1
+ # Application RwdTinker orginally (c) 2004 Steven Gibson under GPL.
2
+ # This application is a framework for writing programs from RubyWebDialogs
3
+ # http://www.erikveen.dds.nl/rubywebdialogs/index.html
4
+ # For more information about RwdTinker see http://www.rubyforge.net/projects/rwdapplications
5
+
6
+ # return the version constant defined in the config file
7
+ def runrwdtorrentversion
8
+ @rwd_window = "applicationversion"
9
+ @versionappnamedisplay = "RwdTorrent"
10
+ @versioncopyrightdisplay = "(c) 2005 Steven Gibson "
11
+ @versionnumberdisplay = "Version " + RwdTorrentVersion
12
+
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ # this method adds a new address record
2
+ def saverwdtorrentconfiguration
3
+ require 'fileutils'
4
+
5
+ newname = "rwdtorrent.cnf" # grab the filename to create
6
+ newdata =@a_torrentconfigline1.to_s + "\n" + @a_torrentconfigline2.to_s + "\n" + @a_torrentconfigline3.to_s + "\n" + @a_torrentconfigline4.to_s + "\n" + @a_torrentconfigline5.to_s + "\n" + @a_torrentconfigline6.to_s + "\n" + @a_torrentconfigline7.to_s + "\n" + @a_torrentconfigline8.to_s + "\n" + @a_torrentconfigline9.to_s + "\n"+ @a_torrentconfigline10.to_s + "\n"+ @a_torrentconfigline11.to_s + "\n"+ @a_torrentconfigline9.to_s + "\n"
7
+
8
+ begin # exception trapped block
9
+ fileName = File.join( ConfigurationDir, newname )
10
+ fd = File.open(fileName,"w")
11
+ fd.print(newdata) # save the record info to the file
12
+ fd.close
13
+ @newconfigurationresult=newdata # show the record info in the browser
14
+ rescue SystemCallError, StandardError
15
+ $stderr.print "system call error: " + $!
16
+ end # exception rescue
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ # Application rwdtinker orginally (c) 2004 Steven Gibson under GPL.
2
+ #
3
+ # For more information about see http://www.rubyforge.net/projects/rwdapplications
4
+
5
+ # call the window
6
+ def stoptorrentwindow
7
+ $temptorrentnumber = 0
8
+ Process.kill("SIGHUP", $torrentpid)
9
+ @rwd_window = "main"
10
+ @rwd_tab = "superantcomtorrenttab"
11
+ end
12
+
@@ -0,0 +1,20 @@
1
+
2
+
3
+ def viewtorrentlist
4
+
5
+ commandtext = TorrentListCmd + $rwdtorrentdownloads
6
+
7
+ begin # exception trapped block
8
+
9
+
10
+
11
+
12
+ @a_viewtorrentdisplay =`#{commandtext}`
13
+
14
+ rescue SystemCallError, StandardError
15
+ $stderr.print "system call error: " + $!
16
+ end # exception rescue
17
+
18
+ end
19
+
20
+
@@ -0,0 +1,36 @@
1
+
2
+
3
+ def viewtorrentfile
4
+
5
+ commandtext = "ruby extras/aversa.rb --decode torrentfiles/" + @a_viewtorrent.to_s + ".torrent "
6
+
7
+ begin # exception trapped block
8
+
9
+
10
+
11
+
12
+ @a_torrentdata =`#{commandtext}`
13
+
14
+ rescue SystemCallError, StandardError
15
+ $stderr.print "system call error: " + $!
16
+ end # exception rescue
17
+
18
+ end
19
+ def viewtorrentfilehttp
20
+
21
+ commandtext = "ruby extras/aversa.rb --decode " + @a_viewtorrenthttp.to_s
22
+
23
+ begin # exception trapped block
24
+
25
+
26
+ print commandtext
27
+ @a_torrentdata =`#{commandtext}`
28
+
29
+ rescue SystemCallError, StandardError
30
+ $stderr.print "system call error: " + $!
31
+ end # exception rescue
32
+
33
+ end
34
+
35
+
36
+
@@ -0,0 +1,4 @@
1
+
2
+
3
+ end # end of rwdtinker class
4
+
@@ -0,0 +1,7 @@
1
+ ##VERSION:1.57
2
+ #language selection file
3
+ ##NAME:$lang:0
4
+ #$lang = "jp"
5
+ $lang= "en"
6
+ #$lang= "nl"
7
+ #$lang= "es"
@@ -0,0 +1,3 @@
1
+ ##VERSION:1.57
2
+ $rwdapplicationidentity = "rwdtorrent bittorrent gui"
3
+
@@ -0,0 +1,15 @@
1
+ ##VERSION:1.61
2
+ ConfigurationDir = "configuration" # for use in program - init.rb has this value without using this constant
3
+ CodeName = "rwdtinker"
4
+ CodeNameFile = CodeName + ".rb"
5
+ RWDFile = "rwdtinker.rwd"
6
+ LangDir = "lang"
7
+ CodeDir = "code"
8
+ GuiDir = "gui"
9
+ $help_topic = "general_help"
10
+ $helptopicsarray = [ "general_help","network_help"]
11
+ $prevouswindow ="main"
12
+ $rwdcontrolports =["13713","13714","13715","13716","13717","13718"]
13
+ $port = 7705
14
+
15
+ RwdTinkerVersion = "1.61"
@@ -0,0 +1,11 @@
1
+ ##VERSION:0.01
2
+ ##NAME:$rwdtorrentfilesdir:0
3
+ $rwdtorrentfilesdir="torrentfiles"
4
+ ##NAME:$rwdtorrentdownloads:0
5
+ $rwdtorrentdownloads="downloads"
6
+ ##NAME:$extrasdir:0
7
+ $extrasdir="extras"
8
+ ##NAME:TorrentListCmd:0
9
+ TorrentListCmd="ls -s -1 -h -R "
10
+
11
+ RwdTorrentVersion = "0.01"
@@ -0,0 +1,17 @@
1
+ ##VERSION:1.57
2
+ TinkerWin2ConfigurationFileName = "tinkerwin2variables.cnf" # this file name - do not change
3
+ ##NAME:$zipslocation:0
4
+ $zipslocation = "zips" # location of applets to add
5
+ $zipsarray = [""] ; $zipsarraylocal = [""]
6
+ ##NAME:$xpcommand:0
7
+ $xpcommand = " " # Linux machines
8
+ # $xpcommand = "cmd /C " # XP machines with cmd shell
9
+ ##NAME:$gemdirectory_withgemfiles:0
10
+ $gemdirectory_withgemfiles = "/usr/lib/ruby/gems/1.8/gems"
11
+ # $gemdirectory_withgemfiles = "c:\\ruby\\lib\\ruby\\gems\\1.8\\gems" # XP machine
12
+ ##NAME:$geminstalled_directory:0
13
+ # $geminstalled_directory = "/ruby/lib/ruby/gems/1.8/gems" # XP machine
14
+ $geminstalled_directory = "/usr/lib/ruby/gems/1.8/gems" # Debian Linux
15
+
16
+ RwdTinkerWin2Version = "0.8"
17
+
@@ -0,0 +1 @@
1
+ Linux
data/ev/browser.rb ADDED
@@ -0,0 +1,109 @@
1
+ require "ev/ruby"
2
+ require "ev/net"
3
+
4
+ begin
5
+ require "win32ole"
6
+ require "win32/registry"
7
+ rescue LoadError
8
+ $".push "win32ole.so"
9
+ $".push "win32/registry.rb"
10
+ end
11
+
12
+ def windowsbrowser
13
+ $stderr.puts "Looking for default browser..."
14
+
15
+ filetype = "htmlfile"
16
+ application = nil
17
+
18
+ begin
19
+ Win32::Registry::HKEY_CLASSES_ROOT.open('.html') do |reg|
20
+ filetype = reg[""]
21
+ end
22
+
23
+ Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + '\shell\open\command') do |reg|
24
+ application = reg[""]
25
+ end
26
+ rescue NameError
27
+ $stderr.puts "Only available for Windows."
28
+ end
29
+
30
+ application
31
+ end
32
+
33
+ def linuxbrowser
34
+ application = ""
35
+
36
+ application = `which galeon 2> /dev/null`.chomp if application.empty?
37
+ application = `which mozilla 2> /dev/null`.chomp if application.empty?
38
+ application = `which firefox 2> /dev/null`.chomp if application.empty?
39
+ application = `which opera 2> /dev/null`.chomp if application.empty?
40
+ application = `which konqueror 2> /dev/null`.chomp if application.empty?
41
+ application = `which htmlview 2> /dev/null`.chomp if application.empty?
42
+ application = nil if application.empty?
43
+
44
+ application
45
+ end
46
+
47
+ def defaultbrowser
48
+ res = nil
49
+ res = windowsbrowser if windows?
50
+ res = linuxbrowser if linux?
51
+ res
52
+ end
53
+
54
+ def showinbrowser(html, browser=defaultbrowser)
55
+ port, io = TCPServer.freeport(7701, 7709)
56
+
57
+ unless browser.nil?
58
+ Thread.new do
59
+ begin
60
+ #command = "1234 \"http://localhost:#{port}\"" if linux?
61
+ #command = "L:/prog/MozillaFirefox/firefox.exe \"http://localhost:#{port}\"" if cygwin?
62
+ #command = Win32::Registry::HKEY_CLASSES_ROOT.open('htmlfile\shell\open\command')[0] + " \"http://localhost:#{port}/\"" if windows?
63
+
64
+ command = "#{browser} \"http://localhost:#{port}\""
65
+
66
+ Thread.pass
67
+
68
+ system(command)
69
+ rescue
70
+ end
71
+ end
72
+ end
73
+
74
+ HTTPServer.serve([port, io]) do |req, resp|
75
+ resp << html
76
+
77
+ resp.stop
78
+ end
79
+ end
80
+
81
+ def tab2html(tab)
82
+ res = ""
83
+
84
+ tab = tab.to_html(false)
85
+
86
+ res << "<html>\n"
87
+ res << "<body>\n"
88
+ res << "<table align='center' border='1' cellspacing='0' cellpadding='3'>\n"
89
+ res << "<tbody>\n"
90
+
91
+ tab.split(/\r*\n/).each do |line|
92
+ res << "<tr>\n"
93
+
94
+ line.split(/\t/, -1).each do |veld|
95
+ veld = "&nbsp;" if veld.compress.empty?
96
+
97
+ res << "<td>%s</td>\n" % veld
98
+ end
99
+
100
+ res << "</tr>\n"
101
+ end
102
+
103
+ res << "</tbody>\n"
104
+ res << "</table>\n"
105
+ res << "</body>\n"
106
+ res << "</html>\n"
107
+
108
+ res
109
+ end
data/ev/ftools.rb ADDED
@@ -0,0 +1,170 @@
1
+ require "ftools"
2
+
3
+ class Dir
4
+ def self.mkdirrec(dir)
5
+ pdir = File.dirname(dir)
6
+
7
+ if not pdir.empty? and not File.directory?(pdir)
8
+ Dir.mkdirrec(pdir)
9
+ end
10
+
11
+ Dir.mkdir(dir) rescue nil
12
+ end
13
+
14
+ def self.copy(from, to)
15
+ if File.directory?(from)
16
+ pdir = Dir.pwd
17
+ todir = File.expand_path(to)
18
+
19
+ mkdirrec(todir)
20
+
21
+ Dir.chdir(from)
22
+ Dir.new(".").each do |e|
23
+ Dir.copy(e, todir+"/"+e) if not [".", ".."].include?(e)
24
+ end
25
+ Dir.chdir(pdir)
26
+ else
27
+ todir = File.dirname(File.expand_path(to))
28
+
29
+ mkdirrec(todir)
30
+
31
+ File.copy(from, to)
32
+ end
33
+ end
34
+
35
+ def self.move(from, to)
36
+ Dir.copy(from, to)
37
+ Dir.rm_rf(from)
38
+ end
39
+
40
+ def self.rm_rf(entry)
41
+ if File.ftype(entry) == "directory"
42
+ pdir = Dir.pwd
43
+
44
+ Dir.chdir(entry)
45
+ Dir.new(".").each do |e|
46
+ Dir.rm_rf(e) if not [".", ".."].include?(e)
47
+ end
48
+ Dir.chdir(pdir)
49
+
50
+ Dir.delete(entry)
51
+ else
52
+ File.delete(entry)
53
+ end
54
+ end
55
+
56
+ def self.find(entry=nil, mask=nil)
57
+ entry = "." if entry.nil?
58
+
59
+ entry = entry.gsub!(/[\/\\]*$/, "") unless entry.nil?
60
+
61
+ mask = /^#{mask}$/i if mask.kind_of?(String)
62
+
63
+ res = []
64
+
65
+ if File.directory?(entry)
66
+ pdir = Dir.pwd
67
+
68
+ res += ["%s/" % entry] if mask.nil? or entry =~ mask
69
+
70
+ begin
71
+ Dir.chdir(entry)
72
+
73
+ begin
74
+ Dir.new(".").each do |e|
75
+ res += Dir.find(e, mask).collect{|e| entry+"/"+e} unless [".", ".."].include?(e)
76
+ end
77
+ ensure
78
+ Dir.chdir(pdir)
79
+ end
80
+ rescue Errno::EACCES => error
81
+ puts error
82
+ end
83
+ else
84
+ res += [entry] if mask.nil? or entry =~ mask
85
+ end
86
+
87
+ res
88
+ end
89
+ end
90
+
91
+ class File
92
+ def self.rollbackup(file, mode=nil)
93
+ backupfile = file + ".RB.BACKUP"
94
+ controlfile = file + ".RB.CONTROL"
95
+ res = nil
96
+
97
+ File.touch(file) unless File.file?(file)
98
+
99
+ # Rollback
100
+
101
+ if File.file?(backupfile) and File.file?(controlfile)
102
+ $stdout.puts "Restoring #{file}..."
103
+
104
+ File.copy(backupfile, file) # Rollback from phase 3
105
+ end
106
+
107
+ # Reset
108
+
109
+ File.delete(backupfile) if File.file?(backupfile) # Reset from phase 2 or 3
110
+ File.delete(controlfile) if File.file?(controlfile) # Reset from phase 3 or 4
111
+
112
+ # Backup
113
+
114
+ File.copy(file, backupfile) # Enter phase 2
115
+ File.touch(controlfile) # Enter phase 3
116
+
117
+ # The real thing
118
+
119
+ if block_given?
120
+ if mode.nil?
121
+ res = yield
122
+ else
123
+ File.open(file, mode) do |f|
124
+ res = yield(f)
125
+ end
126
+ end
127
+ end
128
+
129
+ # Cleanup
130
+
131
+ File.delete(backupfile) # Enter phase 4
132
+ File.delete(controlfile) # Enter phase 5
133
+
134
+ # Return, like File.open
135
+
136
+ res = File.open(file, (mode or "r")) unless block_given?
137
+
138
+ res
139
+ end
140
+
141
+ def self.touch(file)
142
+ File.open(file, "a"){|f|}
143
+ end
144
+
145
+ def self.which(file)
146
+ res = nil
147
+
148
+ if windows?
149
+ file = file.gsub(/\.exe$/i, "") + ".exe"
150
+ sep = ";"
151
+ else
152
+ sep = ":"
153
+ end
154
+
155
+ catch :stop do
156
+ ENV["PATH"].split(/#{sep}/).reverse.each do |d|
157
+ if File.directory?(d)
158
+ Dir.new(d).each do |e|
159
+ if e.downcase == file.downcase
160
+ res = File.expand_path(e, d)
161
+ throw :stop
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ res
169
+ end
170
+ end