lib/drive_info.rb in sensible-cinema-0.21.9 vs lib/drive_info.rb in sensible-cinema-0.21.10

- old
+ new

@@ -14,33 +14,53 @@ You should have received a copy of the GNU General Public License along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>. =end require 'digest/md5' -require 'ruby-wmi' +require 'sane' require 'ostruct' class DriveInfo def self.md5sum_disk(dir) digest = Digest::MD5.new() files = Dir[dir + "VIDEO_TS/*.IFO"] - files.sort.each{|f| + files.sort.each{|f| # sort tends to not do anything... digest << File.binread(f) } raise 'drive might not yet have disc in it? ' + dir unless files.length > 0 digest.hexdigest end def self.get_dvd_drives_as_openstruct - disks = WMI::Win32_LogicalDisk.find(:all) + disks = get_all_drives_as_ostructs disks.select{|d| d.Description =~ /CD-ROM/}.map{|d| d2 = OpenStruct.new; d2.VolumeName = d.VolumeName; d2.Name = d.Name; d2} end -def self.get_drive_with_most_space_with_slash - disks = WMI::Win32_LogicalDisk.find(:all) - most_space = disks.sort_by{|d| d.FreeSpace.to_i}[-1] + def self.get_drive_with_most_space_with_slash + disks = get_all_drives_as_ostructs + most_space = disks.sort_by{|d| d.FreeSpace}[-1] most_space.Name + "\\" -end + end + + def self.get_all_drives_as_ostructs + if OS.mac? + require 'plist' + a = Dir['/Volumes/*'].map{|dir| + parsed = Plist.parse_xml(`diskutil info -plist "#{dir}"`) + d2 = OpenStruct.new + d2.VolumeName = parsed["VolumeName"] + d2.Name = dir # DevNode? + d2.FreeSpace = parsed["FreeSpace"].to_i + d2.Description = parsed['Description'] # work ?? + d2 + } + a + else + require 'ruby-wmi' + disks = WMI::Win32_LogicalDisk.find(:all) + disks.map{|d| d2 = OpenStruct.new; d2.Description = d.Description; d2.VolumeName = d.VolumeName; d2.Name = d.Name; d2.FreeSpace = d.FreeSpace.to_i; d2} + end + end end