narou 3.2.5.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of narou might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +2 -5
- data/.haml-lint.yml +7 -0
- data/.rubocop.yml +23 -5
- data/.scss-lint.yml +9 -0
- data/ChangeLog.md +86 -0
- data/Gemfile.lock +35 -35
- data/README.md +80 -64
- data/lib/backtracer.rb +2 -2
- data/lib/color.rb +5 -1
- data/lib/command.rb +7 -2
- data/lib/command/alias.rb +3 -5
- data/lib/command/backup.rb +3 -5
- data/lib/command/browser.rb +3 -5
- data/lib/command/clean.rb +5 -1
- data/lib/command/console.rb +33 -0
- data/lib/command/convert.rb +143 -117
- data/lib/command/csv.rb +2 -1
- data/lib/command/diff.rb +20 -18
- data/lib/command/download.rb +25 -14
- data/lib/command/folder.rb +3 -5
- data/lib/command/freeze.rb +3 -5
- data/lib/command/help.rb +20 -18
- data/lib/command/init.rb +4 -3
- data/lib/command/inspect.rb +2 -1
- data/lib/command/list.rb +10 -8
- data/lib/command/list/novel_decorator.rb +2 -1
- data/lib/command/log.rb +100 -0
- data/lib/command/log/tail.rb +76 -0
- data/lib/command/mail.rb +20 -17
- data/lib/command/remove.rb +7 -6
- data/lib/command/send.rb +23 -20
- data/lib/command/setting.rb +74 -40
- data/lib/command/tag.rb +16 -15
- data/lib/command/trace.rb +2 -2
- data/lib/command/update.rb +78 -128
- data/lib/command/update/general_lastup_updater.rb +3 -2
- data/lib/command/update/hotentry_manager.rb +2 -1
- data/lib/command/update/interval.rb +2 -1
- data/lib/command/version.rb +2 -1
- data/lib/command/web.rb +17 -3
- data/lib/commandbase.rb +34 -7
- data/lib/commandline.rb +54 -35
- data/lib/converterbase.rb +21 -15
- data/lib/database.rb +3 -2
- data/lib/device.rb +5 -4
- data/lib/device/epub.rb +2 -1
- data/lib/device/ibooks.rb +2 -1
- data/lib/device/ibunko.rb +2 -1
- data/lib/device/kindle.rb +2 -1
- data/lib/device/kobo.rb +2 -1
- data/lib/device/library/cygwin.rb +2 -1
- data/lib/device/library/linux.rb +2 -1
- data/lib/device/library/mac.rb +2 -1
- data/lib/device/library/windows.rb +2 -1
- data/lib/device/library/windows/eject.rb +2 -1
- data/lib/device/reader.rb +2 -1
- data/lib/diffviewer.rb +8 -11
- data/lib/downloader.rb +159 -151
- data/lib/eventable.rb +2 -1
- data/lib/extension.rb +16 -14
- data/lib/extensions/jruby.rb +2 -1
- data/lib/extensions/monkey_patches.rb +7 -0
- data/lib/extensions/monkey_patches/pathname.rb +22 -0
- data/lib/extensions/windows.rb +2 -1
- data/lib/extensions/windows_write_color.rb +2 -1
- data/lib/helper.rb +35 -20
- data/lib/html.rb +2 -1
- data/lib/illustration.rb +2 -1
- data/lib/ini.rb +2 -1
- data/lib/input.rb +2 -1
- data/lib/inspector.rb +3 -2
- data/lib/inventory.rb +3 -3
- data/lib/mailer.rb +3 -2
- data/lib/mixin/all.rb +8 -0
- data/lib/mixin/locker.rb +40 -0
- data/lib/mixin/output_error.rb +28 -0
- data/lib/narou.rb +69 -51
- data/lib/narou/api.rb +2 -4
- data/lib/narou_logger.rb +236 -108
- data/lib/novelconverter.rb +77 -69
- data/lib/novelinfo.rb +4 -2
- data/lib/novelsetting.rb +15 -12
- data/lib/progressbar.rb +13 -9
- data/lib/sitesetting.rb +39 -18
- data/lib/template.rb +5 -4
- data/lib/version.rb +3 -2
- data/lib/web/all.rb +2 -1
- data/lib/web/appserver.rb +83 -65
- data/lib/web/helper4web.rb +10 -5
- data/lib/web/progressbar4web.rb +8 -4
- data/lib/web/public/resources/default-style.css +2 -3
- data/lib/web/public/resources/narou.library.js +86 -60
- data/lib/web/public/resources/narou.queue.js +24 -30
- data/lib/web/public/resources/narou.ui.js +22 -3
- data/lib/web/public/theme/Cerulean/style.css +5 -5
- data/lib/web/public/theme/Darkly/style.css +5 -5
- data/lib/web/public/theme/Readable/style.css +5 -5
- data/lib/web/public/theme/Slate/style.css +2 -3
- data/lib/web/public/theme/Superhero/style.css +2 -3
- data/lib/web/public/theme/United/style.css +5 -5
- data/lib/web/pushserver.rb +10 -7
- data/lib/web/server_helpers.rb +16 -1
- data/lib/web/settingmessages.rb +10 -7
- data/lib/web/streaminginput.rb +2 -1
- data/lib/web/streaminglogger.rb +45 -32
- data/lib/web/views/_about.haml +6 -3
- data/lib/web/views/_header.haml +2 -3
- data/lib/web/views/_move_to_top.haml +2 -0
- data/lib/web/views/_queue.haml +7 -0
- data/lib/web/views/bookmarklet/insert_button.js.erb +1 -1
- data/lib/web/views/index.haml +30 -27
- data/lib/web/views/layout.haml +2 -0
- data/lib/web/views/novels/setting.haml +3 -4
- data/lib/web/views/settings.haml +22 -8
- data/lib/web/views/style.scss +54 -3
- data/lib/web/views/widget/download.haml +9 -3
- data/lib/web/views/widget/drag_and_drop.haml +10 -4
- data/lib/web/web_worker.rb +132 -0
- data/lib/worker.rb +142 -0
- data/narou.gemspec +80 -45
- data/narou.rb +6 -4
- data/template/novel.txt.erb +1 -0
- data/webnovel/kakuyomu.jp.yaml +9 -13
- data/webnovel/ncode.syosetu.com.yaml +3 -1
- data/webnovel/novel18.syosetu.com.yaml +8 -1
- data/webnovel/syosetu.org.yaml +3 -1
- data/webnovel/www.akatsuki-novels.com.yaml +4 -2
- data/webnovel/www.mai-net.net.yaml +3 -1
- metadata +109 -48
- data/lib/web/worker.rb +0 -126
data/lib/eventable.rb
CHANGED
data/lib/extension.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2013 whiteleaf. All rights reserved.
|
5
|
+
#
|
1
6
|
|
2
7
|
require "open-uri"
|
3
8
|
require "openssl"
|
@@ -18,22 +23,19 @@ end
|
|
18
23
|
#
|
19
24
|
require "securerandom"
|
20
25
|
|
21
|
-
def File.write(path, string, *options)
|
22
|
-
|
23
|
-
backup = false
|
24
|
-
temp_path =
|
25
|
-
if File.extname(path) == ".yaml" && File.basename(dirpath) != Downloader::SECTION_SAVE_DIR_NAME
|
26
|
-
backup = true
|
27
|
-
"#{path}.backup"
|
28
|
-
else
|
29
|
-
File.join(dirpath, SecureRandom.hex(15))
|
30
|
-
end
|
26
|
+
def File.write(path, string, *options, mode: nil)
|
27
|
+
return super if mode
|
31
28
|
|
32
|
-
|
29
|
+
dirpath = File.dirname(path)
|
30
|
+
temp_path = File.join(dirpath, SecureRandom.hex(15))
|
31
|
+
if File.extname(path) == ".yaml" && File.basename(dirpath) != Downloader::SECTION_SAVE_DIR_NAME
|
32
|
+
backup = "#{path}.backup"
|
33
|
+
end
|
33
34
|
|
35
|
+
res = super(temp_path, string, *options)
|
34
36
|
if backup
|
35
|
-
super(
|
36
|
-
else
|
37
|
-
File.rename(temp_path, path)
|
37
|
+
super(backup, string, *options)
|
38
38
|
end
|
39
|
+
File.rename(temp_path, path)
|
40
|
+
res
|
39
41
|
end
|
data/lib/extensions/jruby.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2013 whiteleaf. All rights reserved.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "pathname"
|
8
|
+
|
9
|
+
module Narou
|
10
|
+
module MonkyPatches
|
11
|
+
module PathnameGlob
|
12
|
+
# Pathname#glob は Ruby2.5 から実装された
|
13
|
+
def glob(pattern, flags = 0, &block)
|
14
|
+
Pathname.glob(self.join(pattern), flags, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
unless Pathname.method_defined?(:glob)
|
21
|
+
Pathname.prepend(Narou::MonkyPatches::PathnameGlob)
|
22
|
+
end
|
data/lib/extensions/windows.rb
CHANGED
data/lib/helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
5
|
#
|
@@ -15,6 +16,7 @@ module Helper
|
|
15
16
|
|
16
17
|
HOST_OS = RbConfig::CONFIG["host_os"]
|
17
18
|
FILENAME_LENGTH_LIMIT = 50
|
19
|
+
FOLDER_LENGTH_LIMIT = 50
|
18
20
|
|
19
21
|
def os_windows?
|
20
22
|
@@os_is_windows ||= HOST_OS =~ /mswin(?!ce)|mingw|bccwin/i
|
@@ -68,7 +70,7 @@ module Helper
|
|
68
70
|
end
|
69
71
|
case determine_os
|
70
72
|
when :windows
|
71
|
-
system(%!explorer "file:///#{path
|
73
|
+
system(%!explorer "file:///#{path}"!.encode(Encoding::Windows_31J))
|
72
74
|
when :cygwin
|
73
75
|
system(%!cygstart "#{path}"!)
|
74
76
|
when :mac
|
@@ -93,8 +95,10 @@ module Helper
|
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
+
HR_TEXT = "―" * 35
|
99
|
+
|
100
|
+
def print_horizontal_rule(io = $stdout)
|
101
|
+
io.puts HR_TEXT
|
98
102
|
end
|
99
103
|
|
100
104
|
def replace_filename_special_chars(str, invalid_replace = false)
|
@@ -330,7 +334,7 @@ module Helper
|
|
330
334
|
# 数字やスペース、句読点、感嘆符はそのままにする
|
331
335
|
#
|
332
336
|
def to_unprintable_words(string, mask = "●")
|
333
|
-
result = ""
|
337
|
+
result = +""
|
334
338
|
string.each_char do |char|
|
335
339
|
result += case char
|
336
340
|
when /[0-90-9 、。!?!?]/
|
@@ -346,7 +350,8 @@ module Helper
|
|
346
350
|
# 長過ぎるファイルパスを詰める
|
347
351
|
# ファイル名部分のみを詰める。拡張子は維持する
|
348
352
|
#
|
349
|
-
def truncate_path(path, limit =
|
353
|
+
def truncate_path(path, limit = Inventory.load["filename-length-limit"])
|
354
|
+
limit ||= FILENAME_LENGTH_LIMIT
|
350
355
|
dirname = File.dirname(path)
|
351
356
|
extname = File.extname(path)
|
352
357
|
basename = File.basename(path, extname)
|
@@ -359,6 +364,12 @@ module Helper
|
|
359
364
|
end
|
360
365
|
end
|
361
366
|
|
367
|
+
def truncate_folder_title(title, limit = Inventory.load["folder-length-limit"])
|
368
|
+
limit ||= FOLDER_LENGTH_LIMIT
|
369
|
+
return title if title.length <= limit
|
370
|
+
title[0...limit]
|
371
|
+
end
|
372
|
+
|
362
373
|
#
|
363
374
|
# src をERBとして読み込んでから dst に書き出す
|
364
375
|
#
|
@@ -398,11 +409,11 @@ module Helper
|
|
398
409
|
loop do
|
399
410
|
block.call if block
|
400
411
|
sleep(sleep_time)
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
412
|
+
next unless Narou::Worker.canceled?
|
413
|
+
next unless Narou::WebWorker.canceled?
|
414
|
+
Process.kill("KILL", pid)
|
415
|
+
Process.detach(pid)
|
416
|
+
break
|
406
417
|
end
|
407
418
|
end
|
408
419
|
looper.join
|
@@ -411,17 +422,22 @@ module Helper
|
|
411
422
|
stdout.force_encoding(Encoding::UTF_8)
|
412
423
|
stderr.force_encoding(Encoding::UTF_8)
|
413
424
|
return [stdout, stderr, status]
|
425
|
+
rescue RuntimeError => e
|
426
|
+
raise unless e.message.include?("interrupted")
|
427
|
+
process_kill(_pid)
|
428
|
+
raise Interrupt
|
414
429
|
rescue Interrupt
|
415
|
-
|
416
|
-
begin
|
417
|
-
Process.kill("KILL", _pid)
|
418
|
-
Process.detach(_pid) # 死亡確認しないとゾンビ化する
|
419
|
-
rescue
|
420
|
-
end
|
421
|
-
end
|
430
|
+
process_kill(_pid)
|
422
431
|
raise
|
423
432
|
ensure
|
424
|
-
looper
|
433
|
+
looper&.kill
|
434
|
+
end
|
435
|
+
|
436
|
+
def self.process_kill(pid)
|
437
|
+
return unless pid
|
438
|
+
Process.kill("KILL", pid)
|
439
|
+
Process.detach(pid) # 死亡確認しないとゾンビ化する
|
440
|
+
rescue
|
425
441
|
end
|
426
442
|
end
|
427
443
|
|
@@ -516,4 +532,3 @@ module Helper
|
|
516
532
|
end
|
517
533
|
end
|
518
534
|
end
|
519
|
-
|
data/lib/html.rb
CHANGED
data/lib/illustration.rb
CHANGED
data/lib/ini.rb
CHANGED
data/lib/input.rb
CHANGED
data/lib/inspector.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
5
|
#
|
@@ -161,7 +162,7 @@ class Inspector
|
|
161
162
|
num += 1
|
162
163
|
end
|
163
164
|
if num > 0
|
164
|
-
msg = "#{num}個の行末読点を発見しました。"
|
165
|
+
msg = +"#{num}個の行末読点を発見しました。"
|
165
166
|
if num >= END_TOUTEN_COUNT_THRESHOLD
|
166
167
|
msg << "作者による手動改行により改行が多くなっています。" + \
|
167
168
|
"setting.ini の enable_auto_join_line を true にすることをお薦めします。"
|
data/lib/inventory.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
5
|
#
|
@@ -14,7 +15,7 @@ require_relative "narou"
|
|
14
15
|
# scope に :global を指定するとユーザーディレクトリ/.narousetting に保存される
|
15
16
|
#
|
16
17
|
module Inventory
|
17
|
-
def self.load(name, scope = :local)
|
18
|
+
def self.load(name = "local_setting", scope = :local)
|
18
19
|
@@cache ||= {}
|
19
20
|
return @@cache[name] if @@cache[name]
|
20
21
|
{}.tap { |h|
|
@@ -82,4 +83,3 @@ module Inventory
|
|
82
83
|
OpenStruct.new(result)
|
83
84
|
end
|
84
85
|
end
|
85
|
-
|
data/lib/mailer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
5
|
#
|
@@ -20,7 +21,7 @@ class Mailer
|
|
20
21
|
def self.create
|
21
22
|
this = instance
|
22
23
|
this.clear
|
23
|
-
setting_file_path = File.join(Narou.
|
24
|
+
setting_file_path = File.join(Narou.root_dir, SETTING_FILE)
|
24
25
|
if File.exist?(setting_file_path)
|
25
26
|
options = YAML.load_file(setting_file_path)
|
26
27
|
unless options.delete(:complete)
|
data/lib/mixin/all.rb
ADDED
data/lib/mixin/locker.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2013 whiteleaf. All rights reserved.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Narou
|
8
|
+
module Mixin
|
9
|
+
module Locker
|
10
|
+
def locked?(target)
|
11
|
+
id = Downloader.get_id_by_target(target) or return false
|
12
|
+
Inventory.load("lock").include?(id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def lock(target)
|
16
|
+
id = Downloader.get_id_by_target(target)
|
17
|
+
unless id
|
18
|
+
yield if block_given?
|
19
|
+
return
|
20
|
+
end
|
21
|
+
locked_list = Inventory.load("lock")
|
22
|
+
locked_list[id] = Time.now
|
23
|
+
locked_list.save
|
24
|
+
return unless block_given?
|
25
|
+
begin
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
unlock(target)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def unlock(target)
|
33
|
+
id = Downloader.get_id_by_target(target) or return
|
34
|
+
locked_list = Inventory.load("lock")
|
35
|
+
return unless locked_list.delete(id)
|
36
|
+
locked_list.save
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright 2013 whiteleaf. All rights reserved.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Narou
|
8
|
+
module Mixin
|
9
|
+
module OutputError
|
10
|
+
def output_error(io, exception)
|
11
|
+
outputter = proc do
|
12
|
+
io.puts "#{$@.shift}: #{exception.message} (#{exception.class})"
|
13
|
+
$@.each do |b|
|
14
|
+
io.puts " from #{b}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
# MEMO: report_on_exception は Ruby 2.4.0 から実装
|
18
|
+
if Thread.respond_to?(:report_on_exception) && Thread.report_on_exception
|
19
|
+
# report_on_exception が有効な場合は標準出力へのエラー表示はそっちに任せる。
|
20
|
+
# silence を使うことで、標準出力には表示されないがログには記録される
|
21
|
+
io.silence(&outputter)
|
22
|
+
else
|
23
|
+
outputter.call
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/narou.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
#
|
3
4
|
# Copyright 2013 whiteleaf. All rights reserved.
|
4
5
|
#
|
5
6
|
|
6
7
|
require "fileutils"
|
7
8
|
require "memoist"
|
9
|
+
require "pathname"
|
8
10
|
require "active_support/core_ext/object/blank"
|
9
11
|
require_relative "helper"
|
10
12
|
require_relative "inventory"
|
13
|
+
require_relative "mixin/all"
|
11
14
|
if Helper.engine_jruby?
|
12
15
|
require_relative "extensions/jruby"
|
13
16
|
end
|
@@ -19,7 +22,9 @@ module Narou
|
|
19
22
|
AOZORAEPUB3_DIR = "AozoraEpub3"
|
20
23
|
PRESET_DIR = "preset"
|
21
24
|
MISC_DIR = "misc"
|
25
|
+
LOG_DIR = "log"
|
22
26
|
GLOBAL_REPLACE_NAME = "replace.txt"
|
27
|
+
EXIT_SUCCESS = 0
|
23
28
|
EXIT_ERROR_CODE = 127
|
24
29
|
EXIT_INTERRUPT = 126
|
25
30
|
EXIT_REQUEST_REBOOT = 125
|
@@ -31,6 +36,8 @@ module Narou
|
|
31
36
|
"new_arrivals_date" => "新着日", "general_lastup" => "最新話掲載日"
|
32
37
|
}
|
33
38
|
|
39
|
+
extend Mixin::Locker
|
40
|
+
|
34
41
|
class << self
|
35
42
|
extend Memoist
|
36
43
|
|
@@ -40,8 +47,8 @@ module Narou
|
|
40
47
|
2018
|
41
48
|
end
|
42
49
|
|
43
|
-
def
|
44
|
-
|
50
|
+
def root_dir
|
51
|
+
root = nil
|
45
52
|
path = Dir.pwd
|
46
53
|
drive_letter = ""
|
47
54
|
if Helper.os_windows?
|
@@ -51,44 +58,47 @@ module Narou
|
|
51
58
|
end
|
52
59
|
while path != ""
|
53
60
|
if File.directory?("#{drive_letter}#{path}/#{LOCAL_SETTING_DIR_NAME}")
|
54
|
-
|
61
|
+
root = drive_letter + path
|
55
62
|
break
|
56
63
|
end
|
57
64
|
path.gsub!(%r!/[^/]*$!, "")
|
58
65
|
end
|
59
|
-
|
66
|
+
Pathname(root) if root
|
60
67
|
end
|
61
|
-
memoize :
|
68
|
+
memoize :root_dir
|
62
69
|
|
63
70
|
def local_setting_dir
|
64
|
-
|
65
|
-
root_dir = get_root_dir
|
66
|
-
if root_dir
|
67
|
-
local_setting_dir = File.join(root_dir, LOCAL_SETTING_DIR_NAME)
|
68
|
-
end
|
69
|
-
local_setting_dir
|
71
|
+
root_dir&.join(LOCAL_SETTING_DIR_NAME)
|
70
72
|
end
|
71
73
|
memoize :local_setting_dir
|
72
74
|
|
73
75
|
def global_setting_dir
|
74
|
-
root_dir = get_root_dir
|
75
76
|
if root_dir
|
76
|
-
dir =
|
77
|
-
return dir if
|
77
|
+
dir = root_dir.join(GLOBAL_SETTING_DIR_NAME)
|
78
|
+
return dir if dir.directory?
|
78
79
|
end
|
79
|
-
dir =
|
80
|
-
|
80
|
+
dir = Pathname(GLOBAL_SETTING_DIR_NAME).expand_path("~")
|
81
|
+
dir.mkdir unless dir.exist?
|
81
82
|
dir
|
82
83
|
end
|
83
84
|
memoize :global_setting_dir
|
84
85
|
|
85
|
-
def
|
86
|
-
|
86
|
+
def script_dir
|
87
|
+
Pathname(__dir__).join("..").expand_path
|
88
|
+
end
|
89
|
+
memoize :script_dir
|
90
|
+
|
91
|
+
def log_dir
|
92
|
+
root_dir&.join(LOG_DIR)
|
87
93
|
end
|
88
|
-
|
94
|
+
|
95
|
+
def preset_dir
|
96
|
+
script_dir&.join(PRESET_DIR)
|
97
|
+
end
|
98
|
+
memoize :preset_dir
|
89
99
|
|
90
100
|
def already_init?
|
91
|
-
|
101
|
+
root_dir.present?
|
92
102
|
end
|
93
103
|
|
94
104
|
def init
|
@@ -116,17 +126,12 @@ module Narou
|
|
116
126
|
Inventory.load("freeze").include?(id)
|
117
127
|
end
|
118
128
|
|
119
|
-
def get_preset_dir
|
120
|
-
File.expand_path(File.join(get_script_dir, PRESET_DIR))
|
121
|
-
end
|
122
|
-
memoize :get_preset_dir
|
123
|
-
|
124
129
|
def create_aozoraepub3_jar_path(*paths)
|
125
|
-
File.expand_path(File.join(*paths, AOZORAEPUB3_JAR_NAME))
|
130
|
+
Pathname(File.expand_path(File.join(*paths, AOZORAEPUB3_JAR_NAME)))
|
126
131
|
end
|
127
132
|
|
128
133
|
def aozoraepub3_directory?(path)
|
129
|
-
|
134
|
+
create_aozoraepub3_jar_path(path).exist?
|
130
135
|
end
|
131
136
|
|
132
137
|
def parse_replace_txt(text)
|
@@ -148,14 +153,15 @@ module Narou
|
|
148
153
|
end
|
149
154
|
|
150
155
|
def load_global_replace_pattern
|
151
|
-
path =
|
152
|
-
|
153
|
-
|
154
|
-
|
156
|
+
path = root_dir.join(GLOBAL_REPLACE_NAME)
|
157
|
+
pairs =
|
158
|
+
if path.exist?
|
159
|
+
Helper::CacheLoader.memo(path) do |text|
|
160
|
+
parse_replace_txt(text)
|
161
|
+
end
|
162
|
+
else
|
163
|
+
[]
|
155
164
|
end
|
156
|
-
else
|
157
|
-
pairs = []
|
158
|
-
end
|
159
165
|
@@global_replace_pattern_pairs = pairs
|
160
166
|
pairs
|
161
167
|
end
|
@@ -165,7 +171,7 @@ module Narou
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def save_global_replace_pattern
|
168
|
-
path =
|
174
|
+
path = root_dir.join(GLOBAL_REPLACE_NAME)
|
169
175
|
write_replace_txt(path, @@global_replace_pattern_pairs)
|
170
176
|
end
|
171
177
|
|
@@ -173,26 +179,24 @@ module Narou
|
|
173
179
|
# AozoraEpub3 の実行ファイル(.jar)のフルパス取得
|
174
180
|
# 検索順序
|
175
181
|
# 1. グローバルセッティング (global_setting aozoraepub3dir)
|
176
|
-
# 2. 小説保存ディレクトリ(Narou.
|
177
|
-
# 3. スクリプト保存ディレクトリ(Narou.
|
182
|
+
# 2. 小説保存ディレクトリ(Narou.root_dir) 直下の AozoraEpub3
|
183
|
+
# 3. スクリプト保存ディレクトリ(Narou.script_dir) 直下の AozoraEpub3
|
178
184
|
#
|
179
|
-
def
|
185
|
+
def aozoraepub3_path
|
180
186
|
global_setting_aozora_path = Inventory.load("global_setting", :global)["aozoraepub3dir"]
|
181
187
|
if global_setting_aozora_path
|
182
188
|
aozora_jar_path = create_aozoraepub3_jar_path(global_setting_aozora_path)
|
183
|
-
if
|
189
|
+
if aozora_jar_path.exist?
|
184
190
|
return aozora_jar_path
|
185
191
|
end
|
186
192
|
end
|
187
|
-
[Narou.
|
193
|
+
[Narou.root_dir, Narou.script_dir].each do |dir|
|
188
194
|
aozora_jar_path = create_aozoraepub3_jar_path(dir, AOZORAEPUB3_DIR)
|
189
|
-
if
|
190
|
-
return aozora_jar_path
|
191
|
-
end
|
195
|
+
return aozora_jar_path if aozora_jar_path.exist?
|
192
196
|
end
|
193
197
|
nil
|
194
198
|
end
|
195
|
-
memoize :
|
199
|
+
memoize :aozoraepub3_path
|
196
200
|
|
197
201
|
#
|
198
202
|
# 書籍ファイル名を生成する
|
@@ -252,14 +256,14 @@ module Narou
|
|
252
256
|
paths = [File.join(dir, "#{base}#{ext}")]
|
253
257
|
index = 2
|
254
258
|
while File.exist?(path = File.join(dir, "#{base}_#{index}#{ext}"))
|
255
|
-
paths.push(path)
|
259
|
+
paths.push(Pathname(path))
|
256
260
|
index += 1
|
257
261
|
end
|
258
262
|
paths
|
259
263
|
end
|
260
264
|
|
261
|
-
def
|
262
|
-
|
265
|
+
def misc_dir
|
266
|
+
root_dir.join(MISC_DIR)
|
263
267
|
end
|
264
268
|
|
265
269
|
require_relative "device"
|
@@ -293,7 +297,7 @@ module Narou
|
|
293
297
|
end
|
294
298
|
|
295
299
|
def get_theme_dir(name = nil)
|
296
|
-
File.join([
|
300
|
+
Pathname(File.join([script_dir, "lib/web/public/theme", name].compact))
|
297
301
|
end
|
298
302
|
|
299
303
|
def get_theme_names
|
@@ -327,14 +331,14 @@ module Narou
|
|
327
331
|
end
|
328
332
|
|
329
333
|
def commit_version
|
330
|
-
cv_path = File.expand_path("commitversion",
|
334
|
+
cv_path = File.expand_path("commitversion", script_dir)
|
331
335
|
File.read(cv_path) if File.exist?(cv_path)
|
332
336
|
end
|
333
337
|
memoize :commit_version
|
334
338
|
|
335
339
|
def kindlegen_path
|
336
340
|
postfix = Helper.os_windows? ? ".exe" : ""
|
337
|
-
|
341
|
+
aozoraepub3_path.dirname.join("kindlegen#{postfix}")
|
338
342
|
end
|
339
343
|
memoize :kindlegen_path
|
340
344
|
|
@@ -343,5 +347,19 @@ module Narou
|
|
343
347
|
global_setting["line-height"] || default
|
344
348
|
end
|
345
349
|
|
350
|
+
def concurrency_enabled?
|
351
|
+
$stdout != $stdout2
|
352
|
+
end
|
353
|
+
memoize :concurrency_enabled?
|
354
|
+
|
355
|
+
# 同時実行が有効ならキューに積んで、無効なら普通に実行する
|
356
|
+
def concurrency_call(&block)
|
357
|
+
if concurrency_enabled?
|
358
|
+
Worker.push(&block)
|
359
|
+
EXIT_SUCCESS
|
360
|
+
else
|
361
|
+
block.call
|
362
|
+
end
|
363
|
+
end
|
346
364
|
end
|
347
365
|
end
|