-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add launchpad module and reorganize folders
- Loading branch information
Showing
10 changed files
with
102 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
require 'launchpad/settings' | ||
require 'launchpad/index' | ||
require 'launchpad/window' | ||
require 'launchpad/gui/application' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'jrubyfx' | ||
|
||
module Launchpad | ||
# Main application which is only created once at launch | ||
class Application < JRubyFX::Application | ||
# Automatically called on {.launch} | ||
def start(stage) | ||
stage.title = 'Launchpad' | ||
stage.width = 800 | ||
stage.height = 600 | ||
stage.show | ||
end | ||
end | ||
end |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,92 @@ | ||
require 'digest' | ||
require 'open-uri' | ||
|
||
# Provides a diff between local and remote file data by maintaining a cache | ||
# with pathnames and md5 hex digests. | ||
class Index | ||
# @param [Hash] options | ||
# @option options [String] :installation_path root installation directory. | ||
# @option options [String] :local_index_path where the local index is cached. | ||
# @option options [String] :remote_index_uri uri for the remote index. | ||
def initialize(options = {}) | ||
@target_dir = Pathname.new options[:target_dir] || Config.installation_path | ||
@local_index_path = options[:local_index_path] || Config.local_index_path | ||
@remote_index_uri = options[:remote_index_uri] || Config.remote_index_uri | ||
end | ||
module Launchpad | ||
# Provides a diff between local and remote file data by maintaining a cache | ||
# with pathnames and md5 hex digests. | ||
class Index | ||
# @param [Hash] options | ||
# @option options [String] :installation_path root installation directory. | ||
# @option options [String] :local_index_path where the local index is saved. | ||
# @option options [String] :remote_index_uri uri for the remote index. | ||
def initialize(options = {}) | ||
@target_dir = Pathname.new options[:target_dir] | ||
@local_index_path = options[:local_index_path] | ||
@remote_index_uri = options[:remote_index_uri] | ||
end | ||
|
||
# @return [Array<String>] | ||
# an array of files that are not present or do not match the remote. | ||
def diff | ||
(remote - local).map(&:first) | ||
end | ||
# @return [Array<String>] | ||
# an array of files that are not present or do not match the remote. | ||
def diff | ||
(remote - local).map(&:first) | ||
end | ||
|
||
# @return [Array<Array<Pathname, String>>] | ||
# an array of pathnames and their md5 digests for the local install. | ||
def local | ||
@local ||= parse_local | ||
end | ||
# @return [Array<Array<Pathname, String>>] | ||
# an array of pathnames and their md5 digests for the local install. | ||
def local | ||
@local ||= parse_local | ||
end | ||
|
||
# @return [Array<Array<Pathname, String>>] | ||
# an array of remote pathnames and their md5 digests from the patcher. | ||
def remote | ||
@remote ||= parse_remote | ||
end | ||
# @return [Array<Array<Pathname, String>>] | ||
# an array of remote pathnames and their md5 digests from the patcher. | ||
def remote | ||
@remote ||= parse_remote | ||
end | ||
|
||
# Updates {#local} with a full scan of the installation directory. | ||
# @return [self] | ||
def scan | ||
@local = [] | ||
recursive_scan | ||
@local = sort local | ||
save | ||
end | ||
# Updates {#local} with a full scan of the installation directory. | ||
# @return [self] | ||
def scan | ||
@local = [] | ||
recursive_scan | ||
@local = sort local | ||
save | ||
end | ||
|
||
private | ||
private | ||
|
||
def parse(file) | ||
file.read.split("\n").map do |line| | ||
line.split(' | ').tap do |path, md5| | ||
[Pathname.new(path), md5.chomp] | ||
def parse(file) | ||
file.read.split("\n").map do |line| | ||
line.split(' | ').tap do |path, md5| | ||
[Pathname.new(path), md5.chomp] | ||
end | ||
end | ||
end | ||
end | ||
|
||
def parse_local | ||
sort File.open(@local_index_path, 'r') { |file| parse file } | ||
rescue Errno::ENOENT | ||
[] | ||
end | ||
def parse_local | ||
sort File.open(@local_index_path, 'r') { |file| parse file } | ||
rescue Errno::ENOENT | ||
[] | ||
end | ||
|
||
def parse_remote | ||
sort Kernel.open(@remote_index_uri) { |file| parse file } | ||
rescue Errno::ENOENT | ||
[] | ||
end | ||
def parse_remote | ||
sort Kernel.open(@remote_index_uri) { |file| parse file } | ||
rescue Errno::ENOENT | ||
[] | ||
end | ||
|
||
def recursive_scan(target = @target_dir) | ||
target.each_child do |pathname| | ||
if pathname.file? | ||
@local << [pathname.to_s, Digest::MD5.file(pathname).to_s] | ||
elsif pathname.directory? | ||
recursive_scan pathname | ||
def recursive_scan(target = @target_dir) | ||
target.each_child do |pathname| | ||
if pathname.file? | ||
@local << [pathname.to_s, Digest::MD5.file(pathname).to_s] | ||
elsif pathname.directory? | ||
recursive_scan pathname | ||
end | ||
end | ||
end | ||
end | ||
|
||
def save | ||
file = File.open(@local_index_path, 'w') | ||
def save | ||
file = File.open(@local_index_path, 'w') | ||
|
||
local.each do |data| | ||
file.write "#{data[0]} | #{data[1]}\n" | ||
end | ||
local.each do |data| | ||
file.write "#{data[0]} | #{data[1]}\n" | ||
end | ||
|
||
file.close | ||
self | ||
end | ||
file.close | ||
self | ||
end | ||
|
||
def sort(list) | ||
list.empty? ? list : list.sort_by(&:first) | ||
def sort(list) | ||
list.empty? ? list : list.sort_by(&:first) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
spec/lib/launchpad/window_spec.rb → spec/lib/launchpad/gui/application_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters