added thing?
This commit is contained in:
parent
3be7c31aa5
commit
e7f6697038
@ -67,7 +67,7 @@ $CONFIG[:install_dir] = Dir.new(Dir.home) / '.opt'
|
||||
$CONFIG[:desktop_path] = $CONFIG[:install_dir] / 'Discord' / 'discord.desktop'
|
||||
File.mkdir($CONFIG[:install_dir]) if not File.exist?($CONFIG[:install_dir])
|
||||
$CONFIG[:discord_path] = $CONFIG[:install_dir] / 'Discord'
|
||||
$CONFIG[:desktop_file_path] = $CONFIG[:discord_path] / 'discord.desktop'
|
||||
$CONFIG[:desktop_file_path] = $CONFIG[:local_application_install_dir] / 'discord.desktop'
|
||||
$CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_info.json'
|
||||
$CONFIG[:action] = 'install'
|
||||
$CONFIG[:keep_installer] = false
|
||||
@ -145,10 +145,34 @@ end.parse!
|
||||
|
||||
|
||||
# BEGIN: Helper Classes
|
||||
class DesktopFile
|
||||
@@file = File.open($CONFIG[:desktop_path])
|
||||
@@installed_file = File.open($CONFIG[:desktop_file_path])
|
||||
|
||||
def needs_update?
|
||||
@@installed_file.read() != contents
|
||||
end
|
||||
|
||||
def update
|
||||
if needs_update?
|
||||
File.open(@@file, 'w') do |file|
|
||||
puts "Updating Desktop File, changes are needed"
|
||||
file.write(contents)
|
||||
end
|
||||
|
||||
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
||||
%x[ desktop-file-install --dir=#{$CONFIG[:local_application_install_dir]} #{$CONFIG[:desktop_path]} ]
|
||||
else
|
||||
puts "Not updating file. Changes not needed"
|
||||
end
|
||||
end
|
||||
end
|
||||
DISCORD_DESKTOP_TEMPLATE.def_method(DesktopFile, 'contents')
|
||||
|
||||
class Installer
|
||||
URL_DOWNLOAD_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||
@@desktop_file = DesktopFile.new
|
||||
|
||||
def needs_update?
|
||||
local_version < remote_version
|
||||
@ -208,7 +232,7 @@ class Installer
|
||||
end
|
||||
end
|
||||
|
||||
update_desktop_file
|
||||
@@desktop_file.update
|
||||
end
|
||||
end
|
||||
|
||||
@ -219,30 +243,6 @@ end
|
||||
|
||||
# BEGIN: Helper Functions
|
||||
|
||||
def update_desktop_file
|
||||
file_needs_updating = true
|
||||
puts "update_desktop_file: Checking if desktop entry needs updating"
|
||||
if File.exist?($CONFIG[:desktop_path])
|
||||
puts "update_desktop_file: Desktop file exists, checking if it matches template"
|
||||
File.open($CONFIG[:desktop_path], 'r') do |file|
|
||||
if file.read() == DISCORD_DESKTOP_TEMPLATE.result(binding)
|
||||
puts "update_desktop_file: Desktop file matches template. Not updating"
|
||||
file_needs_updating = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if file_needs_updating
|
||||
File.open($CONFIG[:desktop_path], 'w') do |file|
|
||||
puts "update_desktop_file: Desktop File was written"
|
||||
file.write(DISCORD_DESKTOP_TEMPLATE.result(binding))
|
||||
end
|
||||
|
||||
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
||||
%x[ desktop-file-install --dir=#{$CONFIG[:local_application_install_dir].path} #{$CONFIG[:desktop_path]} ]
|
||||
end
|
||||
end
|
||||
|
||||
def make_backup
|
||||
files = {
|
||||
files: Array.new,
|
||||
@ -277,7 +277,6 @@ def make_backup
|
||||
file_count = files[:files].count
|
||||
files[:files].each_with_index { |file, i|
|
||||
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
|
||||
EOF
|
||||
File.open(file, 'rb') { |file_to_archive|
|
||||
contents = file_to_archive.read()
|
||||
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) { |io|
|
||||
@ -339,7 +338,7 @@ case $CONFIG[:action]
|
||||
make_backup
|
||||
|
||||
when 'update-desktop'
|
||||
update_desktop_file
|
||||
DesktopFile.new.update
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user