Skip to content

Commit

Permalink
v0.5.7
Browse files Browse the repository at this point in the history
- Сообщение об обновлении перенесено в отдельное окно.
- Изменена структура проекта.
- Исправлен баг с зависанием программы при запуске.
  • Loading branch information
VerZsuT committed Apr 29, 2021
1 parent 8ddd9ba commit 5258664
Show file tree
Hide file tree
Showing 34 changed files with 625 additions and 404 deletions.
14 changes: 13 additions & 1 deletion docs/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ <h1 class="h1 red-text">SnowRunner XML Editor Desktop</h1>
</header>

<div class="release">
<h2 class="title">v0.5.6с (рекомендуется)</h2>
<h2 class="title">v0.5.7 (рекомендуется)</h2>
<div class="description">
<ul>
<li>Сообщение об обновлении теперь показывается в отдельном окне, а не в уведомлении windows (сделано для версий windows, не поддерживающих уведомления).</li>
<li>Изменена структура файлов для дальнейшего расширения.</li>
<li>Исправлен баг с зависанием программы при запуске.</li>
</ul>
</div>
<button class="download btn btn-primary" version="v0.5.7">Скачать</button>
</div>

<div class="release">
<h2 class="title">v0.5.6с</h2>
<h3 class="subtitle">Настройки</h3>
<div class="description">
<ul>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"snowrunner-xml-editor-desktop","productName":"SnowRunner XML Editor","version":"0.5.6c","description":"Allows you to visually edit the game's XML files.","repository":{"type":"git","url":"https://github.com/VerZsuT/SnowRunner-XML-Editor-Desktop.git"},"main":"src/index.js","scripts":{"start":"electron-forge start","build":"node preBuild.js && npm run package && node postBuild.js","package":"electron-forge package --platform=win32 --arch=ia32"},"keywords":[],"author":{"name":"VerZsuT","email":"verzsut@gmail.com"},"license":"MIT","config":{"forge":{"packagerConfig":{"ignore":["node_modules","docs","update","postBuild.js","preBuild.js",".gitignore"],"icon":"./src/icons/favicon.ico"}}},"devDependencies":{"@electron-forge/cli":"^6.0.0-beta.54","electron":"^12.0.2"},"dependencies":{}}
{"name":"snowrunner-xml-editor-desktop","productName":"SnowRunner XML Editor","version":"0.5.7","description":"Allows you to visually edit the game's XML files.","repository":{"type":"git","url":"https://github.com/VerZsuT/SnowRunner-XML-Editor-Desktop.git"},"main":"src/app/index.js","scripts":{"start":"electron-forge start","build":"node preBuild.js && npm run package && node postBuild.js","package":"electron-forge package --platform=win32 --arch=ia32"},"keywords":[],"author":{"name":"VerZsuT","email":"verzsut@gmail.com"},"license":"MIT","config":{"forge":{"packagerConfig":{"ignore":["node_modules","docs","postBuild.js","preBuild.js",".gitignore"],"icon":"./src/icons/favicon.ico"}}},"devDependencies":{"@electron-forge/cli":"^6.0.0-beta.54","electron":"^12.0.2"},"dependencies":{}}
1 change: 1 addition & 0 deletions postBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if (existsSync(paths.sxmle_updater)) {
console.log('[POST_BUILD][STAGE_3]: Adding files for auto update...')
rmdirSync(join(paths.sxmle_updater, 'files'), {recursive: true})
renameSync(join(paths.renamed, 'resources', 'app'), join(paths.sxmle_updater, 'files'))
rmdirSync(join(paths.renamed), {recursive: true})
console.log('[POST_BUILD][STAGE_3]: Success.')
}

Expand Down
2 changes: 1 addition & 1 deletion preBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { join } = require('path')

const paths = {
out: join(__dirname, 'out'),
config: join(__dirname, 'src', 'config.json'),
config: join(__dirname, 'src', 'app', 'config.json'),
package: join(__dirname, 'package.json'),
packageLock: join(__dirname, 'package-lock.json'),
public: join(__dirname, '..', 'sxmle_updater', 'public.json')
Expand Down
2 changes: 1 addition & 1 deletion src/config.json → src/app/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.6c",
"version": "0.5.7",
"language": "EN",
"pathToInitial": null,
"pathToDLC": null,
Expand Down
166 changes: 94 additions & 72 deletions src/index.js → src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ const { exec } = require('child_process')
const { app, shell, dialog, BrowserWindow, Notification } = require('electron')
const { readFileSync, readdirSync, lstatSync, existsSync, writeFileSync, unlinkSync, copyFileSync, mkdirSync, rmSync, createWriteStream } = require('fs')
const { join, dirname, basename } = require('path')
const main = require('./scripts/service/main.js')
const main = require('../scripts/service/main.js')
const { createHash } = require('crypto')

const locations = {
publicInfo: 'https://verzsut.github.io/sxmle_updater/public.json',
downloadPage: 'https://verzsut.github.io/SnowRunner-XML-Editor-Desktop/download.html',
updateFiles: 'https://verzsut.github.io/sxmle_updater/files',
updateMap: 'https://verzsut.github.io/sxmle_updater/updateMap.json',
root: join(__dirname, '..', '..'),
config: join(__dirname, 'config.json'),
icon: join(__dirname, 'icons', 'favicon.png'),
icon: join(__dirname, '..', 'icons', 'favicon.png'),
preload: join(__dirname, 'preload.js'),
backupFolder: join(__dirname, 'backups'),
backupInitial: join(__dirname, 'backups', 'initial.pak'),
HTMLFolder: join(__dirname, 'editors'),
translations: join(__dirname, 'scripts', 'translations'),
winrar: join(__dirname, 'scripts', 'winrar'),
temp: join(__dirname, 'scripts', 'temp'),
strings: join(__dirname, 'scripts', 'temp', '[strings]'),
dlc: join(__dirname, 'scripts', 'temp', '[media]', '_dlc'),
classes: join(__dirname, 'scripts', 'temp', '[media]', 'classes')
backupFolder: join(__dirname, '..', 'backups'),
backupInitial: join(__dirname, '..', 'backups', 'initial.pak'),
HTMLFolder: join(__dirname, '..', 'pages'),
translations: join(__dirname, '..', 'scripts', 'translations'),
winrar: join(__dirname, '..', 'scripts', 'winrar'),
temp: join(__dirname, '..', 'scripts', 'temp'),
strings: join(__dirname, '..', 'scripts', 'temp', '[strings]'),
dlc: join(__dirname, '..', 'scripts', 'temp', '[media]', '_dlc'),
classes: join(__dirname, '..', 'scripts', 'temp', '[media]', 'classes')
}

let pathToReturn = null
Expand All @@ -45,11 +46,11 @@ initApp()
initMain()

function init() {
if (!config.ignoreUpdates) {
checkUpdate()
}
if (!config.pathToInitial) {
openFirstSteps()
if (!config.ignoreUpdates) {
checkUpdate()
}
}
else if (checkPaths()) {
config.pathToDLC = locations.dlc
Expand All @@ -59,6 +60,9 @@ function init() {
initDLC()
}
openMain()
if (!config.ignoreUpdates) {
checkUpdate()
}
}
else {
resetConfig()
Expand Down Expand Up @@ -210,6 +214,7 @@ function initMain() {
main.resetConfig = resetConfig
main.restoreInitial = restoreInitial
main.saveConfig = saveConfig
main.update = update
}

function initApp() {
Expand Down Expand Up @@ -348,7 +353,7 @@ function checkPathToDelete(path, map) {
}
}
else {
const relativePath = path2.replace(join(__dirname, '..', '/'), '')
const relativePath = path2.replace(join(locations.root, '/'), '')
if (!map[relativePath]) {
toRemove.push(path2)
}
Expand All @@ -359,11 +364,11 @@ function checkPathToDelete(path, map) {
}

function checkMap(map) {
const toRemove = checkPathToDelete(join(__dirname, '..'), map) || []
const toRemove = checkPathToDelete(locations.root, map) || []
const toCreateOrChange = []

for (const relativePath in map) {
const absolutePath = join(__dirname, '..', relativePath)
const absolutePath = join(locations.root, relativePath)

if (!existsSync(absolutePath)) {
toCreateOrChange.push(relativePath)
Expand All @@ -385,8 +390,60 @@ function checkMap(map) {
return [toRemove, toCreateOrChange]
}

function update() {
const page = openDownload()
page.once('show', () => {
page.webContents.postMessage('download', true)
})
resetConfig(true)
download({
url: locations.updateMap,
fromJSON: true,
inMemory: true,
}, (updateMap) => {
let [toRemove, toCreateOrChange] = checkMap(updateMap)

for (const path of toRemove) {
if (lstatSync(path).isFile()) {
unlinkSync(path)
}
else {
rmSync(path, {
recursive: true
})
}
}

if (toCreateOrChange.length === 0) {
relaunchWithoutSaving = true
reload()
}
const toDownload = []
for (const relativePath of toCreateOrChange) {
const path = join(locations.root, relativePath)
const url = `${locations.updateFiles}/${relativePath.replaceAll('\\', '/')}`

if (!existsSync(dirname(path))) {
createDirForPath(path)
}
toDownload.push({url: url, path: path})
}
download({
array: toDownload,
downloadPage: page,
isRoot: true,
}, () => {
toCreateOrChange = toCreateOrChange.slice(1)
if (toCreateOrChange.length === 0) {
relaunchWithoutSaving = true
reload()
}
})
})
}

function checkUpdate() {
dns.resolve('www.google.com', error => {
dns.resolve('yandex.ru', error => {
if (!error) {
https.get(locations.publicInfo, res => {
res.setEncoding('utf-8')
Expand All @@ -400,57 +457,7 @@ function checkUpdate() {
const data = JSON.parse(rawData)
if (data.latestVersion !== config.version) {
if (data.canAutoUpdate) {
showNotification(getText('[NOTIFICATION]'), `${getText('ALLOW_NEW_VERSION_AUTO')} [${data.latestVersion}]`, () => {
const page = openDownload()
page.once('show', () => {
page.webContents.postMessage('download', true)
})
resetConfig(true)
download({
url: locations.updateMap,
fromJSON: true,
inMemory: true,
}, (updateMap) => {
let [toRemove, toCreateOrChange] = checkMap(updateMap)

for (const path of toRemove) {
if (lstatSync(path).isFile()) {
unlinkSync(path)
}
else {
rmSync(path, {
recursive: true
})
}
}

if (toCreateOrChange.length === 0) {
relaunchWithoutSaving = true
reload()
}
const toDownload = []
for (const relativePath of toCreateOrChange) {
const path = join(__dirname, '..', relativePath)
const url = `${locations.updateFiles}/${relativePath.replaceAll('\\', '/')}`

if (!existsSync(dirname(path))) {
createDirForPath(path)
}
toDownload.push({url: url, path: path})
}
download({
array: toDownload,
downloadPage: page,
isRoot: true,
}, () => {
toCreateOrChange = toCreateOrChange.slice(1)
if (toCreateOrChange.length === 0) {
relaunchWithoutSaving = true
reload()
}
})
})
})
openUpdateMessage(data.latestVersion)
}
else {
showNotification(getText('[NOTIFICATION]'), getText('ALLOW_NEW_VERSION'), () => {
Expand Down Expand Up @@ -574,6 +581,7 @@ function openMain() {

function openFirstSteps() {
const wind = createWindow('firstSteps.html', {width: 550, height: 450})
firstStepsWindow = wind
wind.once('close', () => {
app.quit()
})
Expand Down Expand Up @@ -643,6 +651,20 @@ function openSettings() {
})
}

function openUpdateMessage(version) {
const wind = createWindow('updateMessage.html', {
width: 400,
height: 200,
frame: false,
modal: true,
parent: currentWindow,
resizable: false
})
wind.once('show', () => {
wind.webContents.postMessage('content', version)
})
}

function unpackFiles(callback) {
let loading = null
if (!config.showWinRARWindow) {
Expand Down Expand Up @@ -707,15 +729,15 @@ function saveConfig() {

function createWindow(fileName, args={}) {
const wind = new BrowserWindow({
backgroundColor: '#FFF',
width: args.width || 800,
height: args.height || 600,
resizable: args.resizable !== undefined ? args.resizable : true,
icon: locations.icon,
show: false,
show: args.show || false,
parent: args.parent || null,
modal: args.modal || false,
frame: !(args.frame === false),
paintWhenInitiallyHidden: false,
webPreferences: {
preload: locations.preload,
contextIsolation: false
Expand All @@ -725,7 +747,7 @@ function createWindow(fileName, args={}) {
wind.setMenu(null)
wind.loadFile(join(locations.HTMLFolder, fileName)).then(() => {
wind.show()
wind.focusOnWebView()
wind.focus()
if (devTools) {
wind.webContents.toggleDevTools()
}
Expand Down
File renamed without changes.
Loading

0 comments on commit 5258664

Please sign in to comment.