code/superant.com.rwdtinkerbackwindow/initiateapplets.rb in rwdruby-1.07 vs code/superant.com.rwdtinkerbackwindow/initiateapplets.rb in rwdruby-1.08

- old
+ new

@@ -26,15 +26,12 @@ # integrate the new configuration files def initiateapplet(nametextlocal) debuginitiate = 0 - if $DEBUG - $stderr.puts "starting config load with: #{nametextlocal}" - end + $rwdtinkerlog.info "initiateapplet: starting config load with: #{nametextlocal}" - Dir.chdir($progdir ) #changes the current working directory @confignew = "configuration/" + "#{nametextlocal}.cnf" @configdist = "configuration/" + "#{nametextlocal}.dist" Rconftool::install(@configdist,@confignew) @@ -43,189 +40,106 @@ configfileload = File.open(@configdist){|f| f.read} eval configfileload #load config file - - rescue - - if $DEBUG - $stderr.puts "error in initiateapplets - config load" - end + + $rwdtinkerlog.error "initiateapplet: error in initiateapplets - config load" + debuginitiate += 1 end $tempdoc = " " Dir.chdir($progdir) # change back to top program directory # build the English Language hash file from the parts - languagehashvariable = 'Message.update(' - startlangdir = File.join(LangDir,"en") - #get a list of the files and subdirectories on the starting directory only - alanghash = Array.new(Dir[startlangdir].entries.sort) - #loop through the list, ignore the files and add all new directories found - alanghash.each do |x| - #if a directory... - if(test(?d,x)) - # add to the original list of directories - @@tmproot = x + "/**" - #adds the new ones to the array - blanghash = Dir[@@tmproot].entries.sort - blanghash.each do |x| - if(test(?d,x)) - alanghash.push(x) #appends to the end of the array... - end - end - end - end - alanghash.each do |x| - #if it is a file... - if(!test(?d,x)) - alanghash.delete(x) - else #it is a directory... - findfiles(x + "/**") - end - end + require 'lib/rwdtinker/rwdlangdir' + + tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,"en") - #writes the contents of doc into the languagehashvariable - - languagehashvariable = languagehashvariable + $tempdoc + ' :rwdtinker => "Rwdtinker" ) ;' + languagehashvariable = tempdoc # END of en Lang building $tempdoc = " " Dir.chdir($progdir) # change back to top program directory # build the local Language hash file from the parts - startlangdir = File.join(LangDir,$lang) - #get a list of the files and subdirectories on the starting directory only - alanghash = Array.new(Dir[startlangdir].entries.sort) - #loop through the list, ignore the files and add all new directories found - alanghash.each do |x| - #if a directory... - if(test(?d,x)) - # add to the original list of directories - @@tmproot = x + "/**" - #adds the new ones to the array - blanghash = Dir[@@tmproot].entries.sort - blanghash.each do |x| - if(test(?d,x)) - alanghash.push(x) #appends to the end of the array... - end - end - end - end - alanghash.each do |x| - #if it is a file... - if(!test(?d,x)) - alanghash.delete(x) - else #it is a directory... - findfiles(x + "/**") - end - end + tempdoc = RwdtinkerTools.findlanguagefiles(LangDir,$lang) + #writes the contents of doc into the variable - #writes the contents of doc into the variable + languagehashvariable = languagehashvariable + tempdoc - languagehashvariable = languagehashvariable + " Message.update(" + $tempdoc + ' :rwdtinker => "Rwdtinker" ) ' - - - - $tempdoc = " " - Dir.chdir($progdir) # change back to top program directory temp = eval( languagehashvariable ) tempguistorage = $rwd_gui_tinker # if gui load fails restore old begin # error trap # build the actual GUI from the gui parts - $tempdoc = " " - #get a list of the files and subdirectories on the starting directory only - a = Array.new(Dir[GuiDir].entries.sort) - #loop through the list, ignore the files and add all new directories found - a.each do |x| - #if a directory... - if(test(?d,x)) - #use this new dir find to add to the original list of directories - @@root = x + "/**" - #adds the new ones to the array - b = Dir[@@root].entries.sort - b.each do |x| - if(test(?d,x)) - a.push(x) #appends to the end of the array... - end - end - end - end - a.each do |x| - #if it is a file... - if(!test(?d,x)) - a.delete(x) - - else #it is a directory... - loadguifile(x + "/**") - - - end - end - -$rwd_gui_tinker = $tempdoc - + tempdoc = " " + require 'lib/rwdtinker/rwdguidir' + + tempdoc = RwdtinkerTools.findguifiles(GuiDir) + + $rwd_gui_tinker = tempdoc + rescue $rwd_gui_tinker = tempguistorage # restore old gui - if $DEBUG - $stderr.puts "error in initiateapplets - gui building" - end + + $rwdtinkerlog.error "error in initiateapplets - gui building" debuginitiate += 1 end begin # error trap -# now load in the code files + # now load in the code files -$tempdoc = "" -tempcodeinstallline = "" + $tempdoc = "" + tempcodeinstallline = "" - @fileName = "installed/" + nametextlocal + ".inf" + @fileName = "installed/" + nametextlocal + ".inf" + + $rwdtinkerlog.debug "initateapplets: loading file: #{@fileName}" - tmpfilearray = File.readlines(@fileName) + tmpfilearray = File.readlines(@fileName) - tmpfilearray.each do |line| + tmpfilearray.each do |line| - tempcodeinstallline = line.chomp - if tempcodeinstallline.include?('code/') - findfiles(tempcodeinstallline + "/**") - tempcoderesult = eval( $tempdoc ) # read the program code and evaluate - end -end + tempcodeinstallline = line.chomp + if tempcodeinstallline.include?('code/') + findfiles(tempcodeinstallline + "/**") + tempcoderesult = eval( $tempdoc ) # read the program code and evaluate + end + end rescue - if $DEBUG - $stderr.puts "error in initiateapplets - code building" - end + + $rwdtinkerlog.error "error in initiateapplets - code building" + debuginitiate += 1 end - setuphelpaboutoptions # update the help about list - setuptinkerdocuments # update the document pull down list - runhelpwindow # update the help menu - showjumplinkoptions # update the application link menu - runrwdtinkerbackwindow # back to applet window + setuphelpaboutoptions # update the help about list + setuptinkerdocuments # update the document pull down list + runhelpwindow # update the help menu + showjumplinkoptions # update the application link menu + runrwdtinkerbackwindow # back to applet window - # resultend = tempcodeinstallline .index("\n",resultstart) - tempresult = @fileName + # resultend = tempcodeinstallline .index("\n",resultstart) + tempresult = @fileName -return " applet loading successful " + tempresult + return " applet loading successful " + tempresult if debuginitiate > 0 return " initiateapplet .." @@ -233,8 +147,24 @@ return " initiateapplet success" end end + +def findfiles(d) + a = Array.new(Dir[d].entries.sort) + #loop through and get the files names + a.each do |x| + #adjust the filters to the files you want to see... + if(!test(?d,x)) + # only rwd files + if x =~ /rb|rwd|txt/ + fileA=File.open("#{x}","r") #opens the file thats in fileName as read only + $tempdoc+=fileA.read #reads the file into the doc string + fileA.close + end + end + end +end