Skip to content

Commit

Permalink
Merge pull request #4 from portapps/develop
Browse files Browse the repository at this point in the history
Fix update.json cannot be written
  • Loading branch information
crazy-max authored Oct 5, 2018
2 parents bc929a0 + b83acdd commit 75b9ab2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.13.3-17 (2018/10/05)

* Fix `update.json` cannot be written
* Write update settings properly

## 2.13.3-16 (2018/10/03)

* Fix Windows desktop notifications not working (Issue #3)
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module github.com/portapps/rocketchat-portable

require github.com/portapps/portapps v0.0.0-20181003012354-d59079af3b41
require (
github.com/kevinburke/go-bindata v3.11.0+incompatible // indirect
github.com/portapps/portapps v0.0.0-20181003012354-d59079af3b41
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/google/logger v0.0.0-20180208223940-54b4ae679a63 h1:rn2mY9gLAFndN3MKX
github.com/google/logger v0.0.0-20180208223940-54b4ae679a63/go.mod h1:tQN+I/DyBt051hEHNEzPgIeyy/GD1WJaKbqPScoDKdY=
github.com/josephspurrier/goversioninfo v0.0.0-20180220052333-42534847954b h1:66x3jAln/h7rEkx8V1c6zAP/IW4tOlN21OLAJ9d1Vvg=
github.com/josephspurrier/goversioninfo v0.0.0-20180220052333-42534847954b/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE=
github.com/kevinburke/go-bindata v3.11.0+incompatible h1:GiPs9jxaG2xY1B5Dt/d/yHUOMlTk14uS35VcmHrdo4I=
github.com/kevinburke/go-bindata v3.11.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/portapps/portapps v0.0.0-20181003012354-d59079af3b41 h1:CAipL/tHrMoOo/m4Z42L9eZCXkokBS9XU81TdBkEXnY=
Expand Down
42 changes: 31 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"encoding/json"
"io"
"io/ioutil"
"os"
Expand All @@ -23,22 +24,41 @@ func init() {

func main() {
Papp.AppPath = AppPathJoin("app")
Papp.DataPath = AppPathJoin("data")
Papp.DataPath = CreateFolder(AppPathJoin("data"))
Papp.Process = PathJoin(Papp.AppPath, "Rocket.Chat.exe")
Papp.Args = nil
Papp.WorkingDir = Papp.AppPath

fo, err := os.Create(path.Join(Papp.DataPath, "update.json"))
if err != nil {
Log.Error("Cannot create update.json:", err)
}
defer fo.Close()
updateSettingsPath := path.Join(Papp.DataPath, "update.json")
if _, err := os.Stat(updateSettingsPath); err == nil {
rawSettings, err := ioutil.ReadFile(updateSettingsPath)
if err == nil {
jsonMapSettings := make(map[string]interface{})
json.Unmarshal(rawSettings, &jsonMapSettings)
Log.Info("Current update settings:", jsonMapSettings)

_, err = io.Copy(fo, strings.NewReader(`{
"autoUpdate": false
}`))
if err != nil {
Log.Error("Cannot write to update.json:", err)
jsonMapSettings["autoUpdate"] = false
jsonMapSettings["canUpdate"] = false
Log.Info("New settings:", jsonMapSettings)

jsonSettings, err := json.Marshal(jsonMapSettings)
if err != nil {
Log.Error("Update settings marshal:", err)
}
err = ioutil.WriteFile(updateSettingsPath, jsonSettings, 0644)
if err != nil {
Log.Error("Write Update settings:", err)
}
}
} else {
fo, err := os.Create(updateSettingsPath)
if err != nil {
Log.Error("Cannot create update.json:", err)
}
defer fo.Close()
if _, err = io.Copy(fo, strings.NewReader(`{"autoUpdate":false,"canUpdate":false}`)); err != nil {
Log.Error("Cannot write to update.json:", err)
}
}

shortcutPath := path.Join(os.Getenv("APPDATA"), "Microsoft", "Windows", "Start Menu", "Programs", "Rocket.Chat Portable.lnk")
Expand Down

0 comments on commit 75b9ab2

Please sign in to comment.