(feature): windows support

This commit is contained in:
TheDevisi
2026-04-11 12:49:46 +03:00
parent 6709e443e0
commit 86339e69b9
4 changed files with 35 additions and 19 deletions

View File

@@ -7,36 +7,37 @@ import (
)
type Config struct {
Os string
DNS string `json:"dns"` // todo
EncryptionKey string `json:"encryption_key"`
SocksPort string `json:"socks_port"`
ConferenceID string `json:"conference_id"`
}
func getConfigPath() string {
home, err := os.UserHomeDir()
func (p *Program) getConfigPath() string {
dir, err := os.UserConfigDir()
if err != nil {
log("WARNING: Could not get home directory: %v", err)
return "./olcrtc_config.json"
log("WARNING: Could not get system config directory: %v", err)
return "config.json"
}
configDir := filepath.Join(home, ".olcrtc")
configDir := filepath.Join(dir, "olcrtc")
if err := os.MkdirAll(configDir, 0755); err != nil {
log("WARNING: Could not create config directory: %v", err)
}
return filepath.Join(configDir, "config.json")
}
func loadConfig() *Config {
configPath := getConfigPath()
func (p *Program) loadConfig() *Config {
configPath := p.getConfigPath()
log("Loading config from: %s", configPath)
// default values
cfg := &Config{
DNS: "1.1.1.1",
EncryptionKey: "",
SocksPort: "1080",
ConferenceID: "",
}
data, err := os.ReadFile(configPath)
if err != nil {
if os.IsNotExist(err) {
@@ -46,12 +47,10 @@ func loadConfig() *Config {
}
return cfg
}
if err := json.Unmarshal(data, cfg); err != nil {
if err := json.Unmarshal(data, p.Config); err != nil {
log("WARNING: Could not parse config file: %v", err)
return cfg
}
log("Config loaded successfully")
return cfg
}
@@ -66,7 +65,7 @@ func (p *Program) saveConfig(dns, encryptionKey, socksPort, conferenceID string)
ConferenceID: conferenceID,
}
configPath := getConfigPath()
configPath := p.getConfigPath()
data, err := json.MarshalIndent(p.Config, "", " ")
if err != nil {
log("ERROR: Could not marshal config: %v", err)

View File

@@ -2,6 +2,7 @@ package main
import (
"os/exec"
"runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
@@ -27,11 +28,14 @@ func main() {
func NewProgram() *Program {
log("Initializing program...")
cfg := loadConfig()
uOs := runtime.GOOS
log("RUNTIME: Detected OS - %v", uOs)
p := &Program{
App: app.New(),
Config: cfg,
App: app.New(),
}
cfg := p.loadConfig()
cfg.Os = uOs
p.Config = cfg
p.buildRunString(cfg.ConferenceID, cfg.EncryptionKey, cfg.SocksPort, cfg.DNS)
return p
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"time"
)
@@ -16,7 +17,13 @@ func (p *Program) olcrtcRun() {
return
}
p.Cmd = exec.Command("sh", "-c", p.RunString)
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd.exe", "/C", p.RunString)
} else {
cmd = exec.Command("sh", "-c", p.RunString)
}
p.Cmd = cmd
err := p.Cmd.Start()
if err != nil {
log("ERROR: Failed to start olcrtc: %v", err)

View File

@@ -61,8 +61,14 @@ func (p *Program) buildRunString(conferenceId, encryptionKey, socksPort, dns str
log(" Encryption Key: %s", encryptionKey)
log(" Socks Port: %s", socksPort)
log(" DNS Server: %s", dns)
p.RunString = fmt.Sprintf("./olcrtc -mode cnc -id \"%s\" -key \"%s\" -socks-port %s", conferenceId, encryptionKey, socksPort)
switch p.Config.Os {
case "windows":
p.RunString = fmt.Sprintf("olcrtc.exe -mode cnc -id \"%s\" -key \"%s\" -socks-port %s", conferenceId, encryptionKey, socksPort)
case "linux", "darwin":
p.RunString = fmt.Sprintf("./olcrtc -mode cnc -id \"%s\" -key \"%s\" -socks-port %s", conferenceId, encryptionKey, socksPort)
default: // in case for freeBSD and etc
p.RunString = fmt.Sprintf("olcrtc -mode cnc -id \"%s\" -key \"%s\" -socks-port %s", conferenceId, encryptionKey, socksPort)
}
log("Generated command: %s", p.RunString)
}