Skip to content

Commit

Permalink
v0.5.5
Browse files Browse the repository at this point in the history
- Процесс обновлений полностью автоматизирован.
- Размер обновлений уменьшен более чем в 5 раз.
- Скачивается лишь те файлы, которые были изменены в обновлении.
  • Loading branch information
VerZsuT committed Apr 27, 2021
1 parent a36382e commit cdb2c0a
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 122 deletions.
14 changes: 13 additions & 1 deletion docs/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
<h1 class="h1 red-text">SnowRunner XML Editor Desktop</h1>
</header>

<div class="release">
<h2 class="title">v0.5.5 (рекомендуется)</h2>
<h3 class="subtitle">Автообновления</h3>
<div class="description">
<ul>
<li>Процесс обновлений полностью автоматизирован.</li>
<li>Размер обновлений уменьшен более чем в 5 раз.</li>
<li>Скачивается лишь те файлы, которые были изменены в обновлении.</li>
</ul>
</div>
<button class="download btn btn-primary" version="v0.5.5">Скачать</button>
</div>

<div class="release">
<h2 class="title">v0.5.4 (рекомендуется)</h2>
<div class="description">
Expand All @@ -28,7 +41,6 @@ <h2 class="title">v0.5.4 (рекомендуется)</h2>
<li>Самые полезные настройки теперь отмечены жирным шрифтом.</li>
<li>Добавлена кнопка "назад" в редакторе.</li>
<li>Перемещена и изменена кнопка "сохранить" в редакторе.</li>
<li><b>26.04.2021</b>: размер обновлений уменьшен в 5 раз. Обновление автоматизировано (не надо скачивать вручную).</li>
</ul>
</div>
<button class="download btn btn-primary" version="v0.5.4">Скачать</button>
Expand Down
2 changes: 1 addition & 1 deletion docs/public.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"latestVersion":"0.5.4","canAutoUpdate":true}
{"latestVersion":"0.5.5","canAutoUpdate":true}
Binary file modified docs/update.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/update/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snowrunner-xml-editor-desktop",
"productName": "SnowRunner XML Editor",
"version": "0.5.4",
"version": "0.5.5",
"description": "Allows you to visually edit the game's XML files.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion docs/update/src/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.4",
"version": "0.5.5",
"language": "EN",
"pathToInitial": null,
"pathToDLC": null,
Expand Down
100 changes: 46 additions & 54 deletions docs/update/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,49 +266,25 @@ function createDirForPath(path) {
}

function download(params, cb) {
if (!params.inMemory) {
const file = createWriteStream(params.dest)
https.get(params.url, res => {
res.pipe(file)
https.get(params.url, res => {
let rawData = ''

res.on('end', () => {
file.once('close', () => {
cb()
})
file.close()
})

res.on('error', error => {
file.once('close', () => {
unlinkSync(params.dest)
cb(error)
})
file.close()
})
res.on('data', chunk => {
rawData += chunk
})
} else {
https.get(params.url, res => {
res.setEncoding('utf-8')
let rawData = ''

res.on('data', (chunk) => {
rawData += chunk
})

res.on('end', () => {
if (params.fromJSON) {
cb(null, JSON.parse(rawData))
} else {
cb(null, rawData)
}
})
res.on('end', () => {
if (params.fromJSON) {
cb(null, JSON.parse(rawData))
} else {
cb(null, rawData)
}
})

res.on('error', error => {
cb(error)
})
res.on('error', error => {
cb(error)
})
}

})
}

function checkPathToDelete(path, map) {
Expand All @@ -317,7 +293,7 @@ function checkPathToDelete(path, map) {
for (const item of items) {
const path2 = join(path, item)

if (!lstatSync(path2).isFile()) {
if (lstatSync(path2).isDirectory()) {
const array = checkPathToDelete(path2, map)
if (array) {
toRemove.push(...array)
Expand All @@ -335,23 +311,23 @@ function checkPathToDelete(path, map) {
}

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

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

if (!existsSync(absolutePath)) {
toCreateOrChange.push(absolutePath)
toCreateOrChange.push(relativePath)
}
else {
if (!lstatSync(absolutePath).isFile()) {
toRemove.push(absolutePath)
if (lstatSync(absolutePath).isDirectory()) {
toRemove.push(relativePath)
}
const shaHash = createHash('sha1')
shaHash.update(readFileSync(absolutePath).toString())
if (shaHash.digest('hex') !== map[relativePath]) {
toCreateOrChange.push(absolutePath)
toCreateOrChange.push(relativePath)
}
}
}
Expand All @@ -375,31 +351,47 @@ function checkUpdate() {
if (data.latestVersion !== config.version) {
if (data.canAutoUpdate) {
showNotification(getText('[NOTIFICATION]'), getText('ALLOW_NEW_VERSION_AUTO'), () => {
openDownload()
download({
url: locations.updateMap,
inMemory: true,
fromJSON: true
}, (_error, updateMap) => {
const [toRemove, toCreateOrChange] = checkMap(updateMap)
openDownload()

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

let checker = toCreateOrChange
if (toCreateOrChange.length === 0) {
relaunchWithoutSaving = true
app.relaunch()
app.quit()
}
for (const relativePath of toCreateOrChange) {
const path = join(__dirname, relativePath)
const path = join(__dirname, '..', relativePath)
const url = `${locations.update}/${relativePath.replaceAll('\\', '/')}`
download({
url: `${locations.update}/${relativePath.replaceAll('\\', '/')}`,
inMemory: true
url: url,
}, (_error, data) => {
if (!existsSync(dirname(path))) {
createDirForPath(path)
}
writeFileSync(path, data)
relaunchWithoutSaving = true
app.relaunch()
app.quit()
checker = checker.filter(item => item !== relativePath)
if (checker.length === 0) {
relaunchWithoutSaving = true
app.relaunch()
app.quit()
}
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion docs/updateMap.json

Large diffs are not rendered by default.

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.4","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-win-x86 && npm run package-win-x64 && node postBuild.js","package-win-x86":"electron-forge package --platform=win32 --arch=ia32","package-win-x64":"electron-forge package --platform=win32 --arch=x64"},"keywords":[],"author":{"name":"VerZsuT","email":"verzsut@gmail.com"},"license":"MIT","config":{"forge":{"packagerConfig":{"ignore":["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":{}}
{"name":"snowrunner-xml-editor-desktop","productName":"SnowRunner XML Editor","version":"0.5.5","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-win-x86 && npm run package-win-x64 && node postBuild.js","package-win-x86":"electron-forge package --platform=win32 --arch=ia32","package-win-x64":"electron-forge package --platform=win32 --arch=x64"},"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":{}}
55 changes: 38 additions & 17 deletions postBuild.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { execSync } = require('child_process')
const { renameSync, unlinkSync } = require('fs')
const { createHash } = require('crypto')
const { renameSync, unlinkSync, readdirSync, statSync, readFileSync, writeFileSync, rmdirSync, copyFile } = require('fs')
const { join } = require('path')

const paths = {
Expand All @@ -14,32 +15,52 @@ const paths = {

console.log('[POST_BUILD][LOG]: Processing post build...')

console.log('[POST_BUILD][STAGE_1]: Renaming builds...')
console.log('[POST_BUILD][STAGE_1]: Renaming x86...')
renameSync(paths.x86, paths.x86_renamed)
console.log('[POST_BUILD][STAGE_1]: x86 renamed.')
console.log('[POST_BUILD][STAGE_1]: Success.')
console.log('[POST_BUILD][STAGE_1]: Renaming x64...')
renameSync(paths.x64, paths.x64_renamed)
console.log('[POST_BUILD][STAGE_1]: x64 renamed.')
console.log('[POST_BUILD][STAGE_1]: Builds renamed.')
console.log('[POST_BUILD][STAGE_1]: Success.')

console.log('[POST_BUILD][LOG]................')

console.log('[POST_BUILD][STAGE_2]: Archiving builds...')
console.log('[POST_BUILD][STAGE_2]: Archiving x86...')
execSync(`WinRAR a -ibck -ep1 -m5 "${join(paths.out, 'SnowRunnerXMLEditor_x86.rar')}" "${paths.x86_renamed}"`, {
cwd: paths.winrar
})
console.log('[POST_BUILD][STAGE_2]: x86 archived.')

console.log('[POST_BUILD][STAGE_3]: Archiving x64...')
console.log('[POST_BUILD][STAGE_2]: Success.')
console.log('[POST_BUILD][STAGE_2]: Archiving x64...')
execSync(`WinRAR a -ibck -ep1 -m5 "${join(paths.out, 'SnowRunnerXMLEditor_x64.rar')}" "${paths.x64_renamed}"`, {
cwd: paths.winrar
})
console.log('[POST_BUILD][STAGE_3]: x64 archived.')
console.log('[POST_BUILD][STAGE_2]: Builds archived.')
console.log('[POST_BUILD][STAGE_2]: Success.')

console.log('[POST_BUILD][STAGE_4]: Archiving files to auto update...')
unlinkSync(join(paths.docs, 'update.zip'))
execSync(`WinRAR a -ibck -ep1 -m5 "${join(paths.docs, 'update.zip')}" "${join(paths.x64_renamed, 'resources', 'app')}"`, {
cwd: paths.winrar
})
console.log('[POST_BUILD][STAGE_4]: Files to auto update archived.')
console.log('[POST_BUILD][LOG]................')

console.log('[POST_BUILD][STAGE_3]: Adding files for auto update...')
rmdirSync(join(paths.docs, 'update'), {recursive: true})
renameSync(join(paths.x86_renamed, 'resources', 'app'), join(paths.docs, 'update'))
console.log('[POST_BUILD][STAGE_3]: Success.')
console.log('[POST_BUILD][STAGE_3]: Generating files map for auto update...')
writeFileSync(join(paths.docs, 'updateMap.json'), JSON.stringify(generateMap(join(paths.x64_renamed, 'resources', 'app'))))
console.log('[POST_BUILD][STAGE_3]: Success.')

console.log('[POST_BUILD][LOG]: Success.')

function generateMap(rootPath) {
let map = {}
const items = readdirSync(rootPath)
for (const item of items) {
const path = join(rootPath, item)
const stats = statSync(path)

if (!stats.isFile()) {
map = Object.assign(map, generateMap(path))
} else {
const shaHash = createHash('sha1')
shaHash.update(readFileSync(path).toString())
map[path.replace(join(paths.x64_renamed, 'resources', 'app', '/'), '')] = shaHash.digest('hex').toString()
}
}
return map
}
29 changes: 19 additions & 10 deletions preBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,37 @@ fs.mkdirSync(paths.out)

console.log('[PRE_BUILD][LOG]: Processing pre build...')

console.log('[PRE_BUILD][STAGE_1]: Reading files...')
console.log('[PRE_BUILD][STAGE_1]: Reading config.json...')
const config = JSON.parse(fs.readFileSync(paths.config).toString())
console.log('[PRE_BUILD][STAGE_1]: config.json readed.')
console.log('[PRE_BUILD][STAGE_1]: Success.')
console.log('[PRE_BUILD][STAGE_1]: Reading package.json...')
const package = JSON.parse(fs.readFileSync(paths.package).toString())
console.log('[PRE_BUILD][STAGE_1]: package.json readed.')
console.log('[PRE_BUILD][STAGE_1]: Success.')
console.log('[PRE_BUILD][STAGE_1]: Reading package-lock.json...')
const packageLock = JSON.parse(fs.readFileSync(paths.packageLock).toString())
console.log('[PRE_BUILD][STAGE_1]: package-lock.json readed.')
console.log('[PRE_BUILD][STAGE_1]: Success.')
console.log('[PRE_BUILD][STAGE_1]: Reading public.json...')
const public = JSON.parse(fs.readFileSync(paths.public).toString())
console.log('[PRE_BUILD][STAGE_1]: public.json readed.')
console.log('[PRE_BUILD][STAGE_1]: Success.')

console.log('[PRE_BUILD][LOG]................')

console.log('[PRE_BUILD][STAGE_2]: Setting properties...')
package.version = config.version
packageLock.version = config.version
public.latestVersion = config.version
console.log('[PRE_BUILD][STAGE_2]: Properties setted.')
console.log('[PRE_BUILD][STAGE_2]: Success.')

console.log('[PRE_BUILD][LOG]................')

console.log('[PRE_BUILD][STAGE_3]: Changing files...')
console.log('[PRE_BUILD][STAGE_3]: Changing package.json...')
fs.writeFileSync(paths.package, JSON.stringify(package))
console.log('[PRE_BUILD][STAGE_3]: package.json changed.')
console.log('[PRE_BUILD][STAGE_3]: Success.')
console.log('[PRE_BUILD][STAGE_3]: Changing package-lock.json...')
fs.writeFileSync(paths.packageLock, JSON.stringify(packageLock))
console.log('[PRE_BUILD][STAGE_3]: package-lock.json changed.')
console.log('[PRE_BUILD][STAGE_3]: Success.')
console.log('[PRE_BUILD][STAGE_3]: Changing public.json...')
fs.writeFileSync(paths.public, JSON.stringify(public))
console.log('[PRE_BUILD][STAGE_3]: public.json changed.')
console.log('[PRE_BUILD][STAGE_3]: Success.')

console.log('[PRE_BUILD][LOG]: Success.')
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.4",
"version": "0.5.5",
"language": "EN",
"pathToInitial": null,
"pathToDLC": null,
Expand Down
Loading

0 comments on commit cdb2c0a

Please sign in to comment.