2017-04-10 00:53:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
|
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-04-10 01:31:34 +00:00
|
|
|
"log"
|
2017-04-14 04:15:40 +00:00
|
|
|
"path/filepath"
|
2017-04-14 04:25:19 +00:00
|
|
|
"strings"
|
2017-04-10 01:15:19 +00:00
|
|
|
|
2017-04-10 00:53:44 +00:00
|
|
|
"github.com/andlabs/ui"
|
2020-12-06 04:46:12 +00:00
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
2017-04-10 00:53:44 +00:00
|
|
|
)
|
|
|
|
|
2017-04-10 01:31:34 +00:00
|
|
|
type logger struct {
|
2017-04-14 16:28:50 +00:00
|
|
|
entry *ui.Entry
|
2017-04-10 01:31:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-14 04:15:40 +00:00
|
|
|
func (l *logger) Write(p []byte) (n int, err error) {
|
2017-04-10 01:45:03 +00:00
|
|
|
ui.QueueMain(func() {
|
2017-04-14 16:28:50 +00:00
|
|
|
l.entry.SetText(strings.Trim(string(p), "\n"))
|
2017-04-10 01:45:03 +00:00
|
|
|
})
|
|
|
|
|
2017-04-10 01:31:34 +00:00
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
2017-04-10 00:53:44 +00:00
|
|
|
func gui() error {
|
|
|
|
return ui.Main(func() {
|
2017-06-26 00:36:56 +00:00
|
|
|
pathSourceEntry := ui.NewEntry()
|
|
|
|
pathSourceButton := ui.NewButton("Browse...")
|
|
|
|
pathSourceBox := ui.NewHorizontalBox()
|
|
|
|
pathSourceBox.Append(pathSourceEntry, true)
|
|
|
|
pathSourceBox.Append(pathSourceButton, false)
|
|
|
|
|
|
|
|
pathTargetEntry := ui.NewEntry()
|
|
|
|
pathTargetButton := ui.NewButton("Browse...")
|
|
|
|
pathTargetBox := ui.NewHorizontalBox()
|
|
|
|
pathTargetBox.Append(pathTargetEntry, true)
|
|
|
|
pathTargetBox.Append(pathTargetButton, false)
|
2017-04-10 00:53:44 +00:00
|
|
|
|
|
|
|
titleEntry := ui.NewEntry()
|
2017-06-26 01:06:41 +00:00
|
|
|
languageEntry := ui.NewEntry()
|
2017-04-14 16:28:50 +00:00
|
|
|
outputEntry := ui.NewEntry()
|
2017-04-12 03:40:53 +00:00
|
|
|
importButton := ui.NewButton("Import dictionary...")
|
2017-04-10 00:53:44 +00:00
|
|
|
|
|
|
|
mainBox := ui.NewVerticalBox()
|
2017-06-26 01:06:41 +00:00
|
|
|
mainBox.Append(ui.NewLabel("Path to dictionary source (CATALOGS file for EPWING)"), false)
|
2017-06-26 00:36:56 +00:00
|
|
|
mainBox.Append(pathSourceBox, false)
|
|
|
|
mainBox.Append(ui.NewLabel("Path to dictionary target ZIP file"), false)
|
|
|
|
mainBox.Append(pathTargetBox, false)
|
2017-06-26 01:06:41 +00:00
|
|
|
mainBox.Append(ui.NewLabel("Dictionary display title (blank for default)"), false)
|
2017-04-10 00:53:44 +00:00
|
|
|
mainBox.Append(titleEntry, false)
|
2017-06-26 01:06:41 +00:00
|
|
|
mainBox.Append(ui.NewLabel("Dictionary glossary language (blank for English)"), false)
|
|
|
|
mainBox.Append(languageEntry, false)
|
|
|
|
mainBox.Append(ui.NewLabel("Application output"), false)
|
2017-04-14 16:28:50 +00:00
|
|
|
mainBox.Append(outputEntry, false)
|
|
|
|
mainBox.Append(ui.NewVerticalBox(), true)
|
2017-04-10 00:53:44 +00:00
|
|
|
mainBox.Append(importButton, false)
|
|
|
|
|
2017-04-14 16:28:50 +00:00
|
|
|
window := ui.NewWindow("Yomichan Import", 640, 320, false)
|
2017-04-10 00:53:44 +00:00
|
|
|
window.SetMargined(true)
|
|
|
|
window.SetChild(mainBox)
|
|
|
|
|
2017-06-26 00:36:56 +00:00
|
|
|
pathSourceButton.OnClicked(func(*ui.Button) {
|
2017-04-10 00:53:44 +00:00
|
|
|
if path := ui.OpenFile(window); len(path) > 0 {
|
2017-06-26 00:36:56 +00:00
|
|
|
pathSourceEntry.SetText(path)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
pathTargetButton.OnClicked(func(*ui.Button) {
|
|
|
|
if path := ui.SaveFile(window); len(path) > 0 {
|
|
|
|
if len(filepath.Ext(path)) == 0 {
|
|
|
|
path += ".zip"
|
|
|
|
}
|
|
|
|
|
|
|
|
pathTargetEntry.SetText(path)
|
2017-04-10 00:53:44 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-04-14 16:28:50 +00:00
|
|
|
log.SetOutput(&logger{outputEntry})
|
2017-04-14 04:15:40 +00:00
|
|
|
|
2017-04-10 01:15:19 +00:00
|
|
|
importButton.OnClicked(func(*ui.Button) {
|
|
|
|
importButton.Disable()
|
2017-04-14 16:28:50 +00:00
|
|
|
outputEntry.SetText("")
|
2017-04-10 01:15:19 +00:00
|
|
|
|
2017-06-26 00:36:56 +00:00
|
|
|
inputPath := pathSourceEntry.Text()
|
|
|
|
if len(inputPath) == 0 {
|
2017-06-26 01:06:41 +00:00
|
|
|
ui.MsgBoxError(window, "Error", "You must specify a dictionary source path")
|
2017-06-26 00:36:56 +00:00
|
|
|
importButton.Enable()
|
2017-04-10 01:15:19 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-06-26 00:36:56 +00:00
|
|
|
outputPath := pathTargetEntry.Text()
|
|
|
|
if len(outputPath) == 0 {
|
2017-06-26 01:06:41 +00:00
|
|
|
ui.MsgBoxError(window, "Error", "You must specify a dictionary target path")
|
|
|
|
importButton.Enable()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
format, err := detectFormat(inputPath)
|
|
|
|
if err != nil {
|
|
|
|
ui.MsgBoxError(window, "Error", "Unable to detect dictionary format")
|
2017-04-10 01:45:03 +00:00
|
|
|
importButton.Enable()
|
2017-04-10 01:15:19 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-04-14 04:30:21 +00:00
|
|
|
title := titleEntry.Text()
|
2017-06-26 01:06:41 +00:00
|
|
|
language := languageEntry.Text()
|
2017-04-14 04:30:21 +00:00
|
|
|
|
2017-04-10 01:45:03 +00:00
|
|
|
go func() {
|
2017-06-26 01:17:00 +00:00
|
|
|
var success bool
|
2017-04-10 01:45:03 +00:00
|
|
|
defer ui.QueueMain(func() {
|
|
|
|
importButton.Enable()
|
2017-06-26 01:17:00 +00:00
|
|
|
if success {
|
|
|
|
ui.MsgBox(window, "Success", "Conversion process complete")
|
|
|
|
} else {
|
|
|
|
ui.MsgBox(window, "Error", "Conversion process failed")
|
|
|
|
}
|
2017-04-10 01:45:03 +00:00
|
|
|
})
|
|
|
|
|
2017-09-10 20:37:40 +00:00
|
|
|
success = exportDb(inputPath, outputPath, format, language, title, defaultStride, false) == nil
|
2017-04-10 01:45:03 +00:00
|
|
|
}()
|
2017-04-10 01:15:19 +00:00
|
|
|
})
|
|
|
|
|
2017-04-10 00:53:44 +00:00
|
|
|
window.OnClosing(func(*ui.Window) bool {
|
|
|
|
ui.Quit()
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
window.Show()
|
|
|
|
})
|
|
|
|
}
|