Skip to content

Commit

Permalink
windoz OK
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlunde committed Sep 25, 2020
1 parent 5c4f454 commit c518506
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This is a Cloud Foundry CLI plugin designed to make it easier when using the [Se
# Requirements
Installed CloudFoundry CLI - ensure that CloudFoundry CLI is installed and working. For more information about installation of CloudFoundry CLI, please visit the official CloudFoundry [documentation](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html).

If you are running from within VSCode, you need to create a Workspace before using the -m (Modify settings.json) option.

# Download and Installation

Check whether you have a previous version installed, using the command: `cf plugins`. If the ServiceManagement plugin is already installed, you need to uninstall it first and then to install the new version. You can uninstall the plugin using command `cf uninstall-plugin ServiceManagement`.
Expand Down
31 changes: 18 additions & 13 deletions ServiceManagement_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,26 @@ func (c *ServiceManagementPlugin) Run(cliConnection plugin.CliConnection, args [

case "windows":
fmt.Println("On Windoz:")

appData := os.Getenv("APPDATA")
fmt.Printf("appData: %s\n", appData)

//APPDATA=C:\Users\I830671\AppData\Roaming
// defaultsFile = "\"" + homeDirectory + "\\AppData\\Roaming\\Code\\storage.json" + "\""
// fmt.Println("defaultsFile: " + defaultsFile)
// byteValue, err := ioutil.ReadFile(defaultsFile)
// if err == nil {
// configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath")
// if err == nil {
// fmt.Println("configURIPath: " + configURIPath)
// settingsFile = "/" + strings.TrimLeft(configURIPath, "file:/")
// inSettings = true // File has sqltools.connections at the top-level
// }
// }
settingsFile = "\"" + homeDirectory + "\\AppData\\Roaming\\Code\\User\\settings.json" + "\""
inSettings = false // File has sqltools.connections at the top-level

defaultsFile = appData + "/Code/storage.json"
fmt.Println("defaultsFile: " + defaultsFile)

byteValue, err := ioutil.ReadFile(defaultsFile)
if err == nil {
configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath")
if err == nil {
fmt.Println("configURIPath: " + configURIPath)
settingsFile = strings.TrimLeft(configURIPath, "file:/")
settingsFile = strings.Replace(settingsFile, "%3A", ":", -1)
//fmt.Println("settingsFile: " + settingsFile)
inSettings = true // File has sqltools.connections at the top-level
}
}
}

fmt.Println("settingsFile: " + settingsFile)
Expand Down
66 changes: 66 additions & 0 deletions windoz_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"os/user"
"runtime"
"strings"

"github.com/buger/jsonparser"
)

func handleError(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
}

func main() {
fmt.Println(runtime.GOOS)
fmt.Println(runtime.GOARCH)

user, err := user.Current()
if err != nil {
log.Fatalf(err.Error())
}
homeDirectory := user.HomeDir
fmt.Printf("Home Directory: %s\n", homeDirectory)

appData := os.Getenv("APPDATA")
fmt.Printf("appData: %s\n", appData)

var defaultsFile = "Unknown"
//var defaultsExists = false

var settingsFile = "Unknown"

defaultsFile = appData + "/Code/storage.json"

fmt.Println("defaultsFile: " + defaultsFile)

_, err = os.Stat(defaultsFile)
handleError(err)

byteValue, err := ioutil.ReadFile(defaultsFile)
if err == nil {
configURIPath, err := jsonparser.GetString(byteValue, "windowsState", "lastActiveWindow", "workspaceIdentifier", "configURIPath")
if err == nil {
fmt.Println("configURIPath: " + configURIPath)
settingsFile = strings.TrimLeft(configURIPath, "file:/")
}
}

settingsFile = strings.Replace(settingsFile, "%3A", ":", -1)

fmt.Println("settingsFile: " + settingsFile)

_, err = os.Stat(settingsFile)
handleError(err)

fmt.Println("OK: Done.")

}

0 comments on commit c518506

Please sign in to comment.