Commit 45010501 by 陶腾飞

加入Error Json,walk.Resouce.Icon()使用绝对路径,修改users.exe的报错机制

parent fe5d1b5a
No preview for this file type
...@@ -3,6 +3,7 @@ import ( ...@@ -3,6 +3,7 @@ import (
"AD-Control/public" "AD-Control/public"
"time" "time"
"flag" "flag"
"strings"
) )
...@@ -52,16 +53,27 @@ func flag_hour(){ ...@@ -52,16 +53,27 @@ func flag_hour(){
switch nh{ switch nh{
case 0: case 0:
public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`) if strings.Index(public.User_computername,"TXHD")!=-1{
public.Execcmd_nowait("shutdown -s -t 300") reboot()
} else{
shutdown()
}
break break
case 1: case 1:
public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`) if strings.Index(public.User_computername,"TXHD")!=-1{
public.Execcmd_nowait("shutdown -s -t 300") reboot()
} else{
shutdown()
}
break break
case 2: case 2:
public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`) if strings.Index(public.User_computername,"TXHD")!=-1{
public.Execcmd_nowait("shutdown -s -t 300") reboot()
} else{
shutdown()
}
break break
case 3: case 3:
public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`) public.MsgBox(`5分钟后,即将关机,运行Z:\tools\【工具】取消关机.bat`)
...@@ -74,3 +86,11 @@ func flag_hour(){ ...@@ -74,3 +86,11 @@ func flag_hour(){
break break
} }
} }
func shutdown(){
public.MsgBox(`5分钟后,即将关机,或者运行Z:\tools\【工具】取消关机.bat`)
public.Execcmd_nowait("shutdown -s -t 300")
}
func reboot(){
public.MsgBox(`5分钟后,即将重启,或者运行Z:\tools\【工具】取消关机.bat`)
public.Execcmd_nowait("shutdown -r -t 300")
}
\ No newline at end of file
No preview for this file type
package main
import (
"fyne.io/fyne/widget"
"fyne.io/fyne/app"
)
func main() {
app := app.New()
w := app.NewWindow("Hello")
w.SetContent(widget.NewVBox(
widget.NewLabel("Hello Fyne!"),
widget.NewButton("Quit", func() {
app.Quit()
}),
))
w.ShowAndRun()
}
\ No newline at end of file
...@@ -9,7 +9,7 @@ const ADServerDaemon string = Env_MainADHostname + DaemonListen ...@@ -9,7 +9,7 @@ const ADServerDaemon string = Env_MainADHostname + DaemonListen
var LocalDaemon string = User_computername + DaemonListen var LocalDaemon string = User_computername + DaemonListen
const DocuBase string = `C:\Users\Public\Documents\AD-Control\` const DocuBase string = `C:\Users\Public\Documents\AD-Control\`
const RandMax int = 60 const RandMax int = 60
const Version string = "0.6" const Version string = "0.7"
const Application string = "AD-Control-Log" const Application string = "AD-Control-Log"
......
...@@ -27,11 +27,16 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte { ...@@ -27,11 +27,16 @@ func DealMsgEnter(ip string,msgtype string,unmsg []byte) []byte {
ret = pmsg.Msg_Deal() ret = pmsg.Msg_Deal()
// 注册表 消息 // 注册表 消息
case Msg_reg: case Msg_Reg:
var pmsg MJreg var pmsg MJreg
ParseJsonBody(unmsg,&pmsg) ParseJsonBody(unmsg,&pmsg)
ret = pmsg.Msg_Deal() ret = pmsg.Msg_Deal()
// 错误 消息
case Msg_Error:
return nil
// var pmsg MJerror
// ParseJsonBody(unmsg,&pmsg)
// ret = pmsg.Msg_Deal()
} }
return JsonToByte(&ret) return JsonToByte(&ret)
...@@ -194,9 +199,7 @@ func (bak * MJbackup)Msg_Deal() interface{}{ ...@@ -194,9 +199,7 @@ func (bak * MJbackup)Msg_Deal() interface{}{
//判断是否有最新版本的文件是否存在 //判断是否有最新版本的文件是否存在
if NotExist(Env_FreeFileSyncExe){ if NotExist(Env_FreeFileSyncExe){
bak.Errorf("FreeFileSync hasn't been installed") SendServerError("FreeFileSync hasn't been installed")
PrintLog(bak.Explain)
SendServer(bak)
return nil return nil
} }
...@@ -220,7 +223,6 @@ func (bak * MJbackup)Msg_Deal() interface{}{ ...@@ -220,7 +223,6 @@ func (bak * MJbackup)Msg_Deal() interface{}{
} }
bak.Explain = "Backup Fill In BatchFile" bak.Explain = "Backup Fill In BatchFile"
bak.PrintExplain()
bak.Status = Msg_Backup_Status_Continue bak.Status = Msg_Backup_Status_Continue
// 交给daemon 处理 Msg_Backup_Status_Continue // 交给daemon 处理 Msg_Backup_Status_Continue
...@@ -233,21 +235,16 @@ func (bak * MJbackup)Msg_Deal() interface{}{ ...@@ -233,21 +235,16 @@ func (bak * MJbackup)Msg_Deal() interface{}{
if !bak.BatchFileExist{ if !bak.BatchFileExist{
PrintLog("init ",string(bak.BatchFileName)) PrintLog("init ",string(bak.BatchFileName))
if err := WriteBytesFile(bak.BatchFileName,bak.BatchFileData);err !=nil{ if err := WriteBytesFile(bak.BatchFileName,bak.BatchFileData);err !=nil{
bak.Errorf("Write Batch File Error "+err.Error()) SendServerError("Write Batch File Error "+err.Error())
return bak return bak
} }
} }
bak.Status = Msg_Backup_Status_Run bak.Status = Msg_Backup_Status_Run
bak.Explain = "Backup Ready" bak.Explain = "Backup Ready"
bak.PrintExplain()
return bak return bak
case Msg_Backup_Status_Run: case Msg_Backup_Status_Run:
SysMsgBox(bak.Computername,bak.Username + " 开始备份") SysMsgBox(bak.Computername,bak.Username + " 开始备份")
PsExec_sd(bak.Computername,Env_FreeFileSyncExe + " "+ bak.BatchFileName) PsExec_sd(bak.Computername,Env_FreeFileSyncExe + " "+ bak.BatchFileName)
case Msg_Backup_Status_Error:
PrintLog(bak.Explain)
default:
PrintLog("Default Backup Json ",bak.Status)
} }
return nil return nil
...@@ -264,3 +261,9 @@ func (reg * MJreg)Msg_Deal() interface{}{ ...@@ -264,3 +261,9 @@ func (reg * MJreg)Msg_Deal() interface{}{
} }
return reg return reg
} }
// 关于 error 错误 的 消息处理
func (err * MJerror)Msg_Deal() interface{}{
return nil
}
\ No newline at end of file
...@@ -14,7 +14,8 @@ const msgerror string = "error" ...@@ -14,7 +14,8 @@ const msgerror string = "error"
const Msg_Report string = "report" const Msg_Report string = "report"
const Msg_Exec string = "exec" const Msg_Exec string = "exec"
const Msg_Backup string = "backup" const Msg_Backup string = "backup"
const Msg_reg string = "reg" const Msg_Reg string = "reg"
const Msg_Error string = "error"
// msg report type /////////////////////////////////////////////////////////// // msg report type ///////////////////////////////////////////////////////////
...@@ -25,7 +26,9 @@ const Msg_Report_OverBak string = "overbak" ...@@ -25,7 +26,9 @@ const Msg_Report_OverBak string = "overbak"
const Msg_Report_CloseWindows string = "closewindows" const Msg_Report_CloseWindows string = "closewindows"
const Msg_Report_OverCopyToWeDrive string = "overcopytowedrive" const Msg_Report_OverCopyToWeDrive string = "overcopytowedrive"
const Msg_Report_OverCopyToDeptShare string = "OverCopyToDeptShare" const Msg_Report_OverCopyToDeptShare string = "OverCopyToDeptShare"
// msg backup status //////////////////////////////////////////////////////////////
// msg backup type //////////////////////////////////////////////////////////////
const Msg_Backup_Status_Start string = "start" const Msg_Backup_Status_Start string = "start"
const Msg_Backup_Status_If string = "if" const Msg_Backup_Status_If string = "if"
...@@ -34,7 +37,7 @@ const Msg_Backup_Status_Run string = "run" ...@@ -34,7 +37,7 @@ const Msg_Backup_Status_Run string = "run"
const Msg_Backup_Status_Error string = msgerror const Msg_Backup_Status_Error string = msgerror
// msg exec status //////////////////////////////////////////////////////////////// // msg exec type ////////////////////////////////////////////////////////////////
const ( const (
Msg_Exec_Cmder_ADServer = iota Msg_Exec_Cmder_ADServer = iota
...@@ -58,6 +61,10 @@ const Msg_Exec_InstallSoftware string = "installsoftware" ...@@ -58,6 +61,10 @@ const Msg_Exec_InstallSoftware string = "installsoftware"
const Msg_Exec_CopyWeDrive string = "copyWeDrive" const Msg_Exec_CopyWeDrive string = "copyWeDrive"
const Msg_Exec_CopyDeptShare string = "copydeptshare" const Msg_Exec_CopyDeptShare string = "copydeptshare"
// msg error type ///////////////////////////////////////////////////////////////
//
const ( const (
Msg_Reg_Query = iota Msg_Reg_Query = iota
Msg_Reg_Read Msg_Reg_Read
...@@ -77,7 +84,6 @@ type MJbase struct{ ...@@ -77,7 +84,6 @@ type MJbase struct{
Computername string `json:"computername"` Computername string `json:"computername"`
Dept string `json:"dept"` Dept string `json:"dept"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
DataBool bool `json:"databool"` DataBool bool `json:"databool"`
DataStr string `json:"datastr"` DataStr string `json:"datastr"`
} }
...@@ -86,7 +92,6 @@ type MJreport struct { ...@@ -86,7 +92,6 @@ type MJreport struct {
MJbase MJbase
Report string `json:"report"` Report string `json:"report"`
Version string `json:"version"` Version string `json:"version"`
} }
// Exec Json Fromat /////////////////////////////////////////////////////// // Exec Json Fromat ///////////////////////////////////////////////////////
...@@ -118,7 +123,9 @@ type MJreg struct{ ...@@ -118,7 +123,9 @@ type MJreg struct{
DataType int `json:"datatype"` DataType int `json:"datatype"`
} }
type MJerror struct{
MJbase
}
// //
// //
...@@ -139,16 +146,12 @@ func (rep * MJreport)init(Report string) { ...@@ -139,16 +146,12 @@ func (rep * MJreport)init(Report string) {
rep.Username = User_name rep.Username = User_name
rep.Dept = User_dept rep.Dept = User_dept
rep.Timestamp = NowTimestamp() rep.Timestamp = NowTimestamp()
rep.Computername = User_computername rep.Computername = User_computername
rep.MsgType = Msg_Report rep.MsgType = Msg_Report
rep.Report = Report rep.Report = Report
rep.Version = Version rep.Version = Version
} }
func (rep * MJreport)PrintExplain(){
PrintLog(rep.Computername,rep.Username,rep.Explain)
}
// Exec // Exec
...@@ -180,7 +183,6 @@ func GJexecInstallSoftware(b bool,s string) interface{}{ ...@@ -180,7 +183,6 @@ func GJexecInstallSoftware(b bool,s string) interface{}{
exec.Command = s exec.Command = s
return exec return exec
} }
func GJexecUserCmd(s string) interface{}{ func GJexecUserCmd(s string) interface{}{
var exec MJexec var exec MJexec
exec.init("") exec.init("")
...@@ -198,8 +200,6 @@ func (exec * MJexec)init(s string){ ...@@ -198,8 +200,6 @@ func (exec * MJexec)init(s string){
exec.SessionID = User_sessionID exec.SessionID = User_sessionID
exec.Cmder = Msg_Exec_Cmder_LocalDaemon exec.Cmder = Msg_Exec_Cmder_LocalDaemon
exec.Status = Msg_Exec_State_Request exec.Status = Msg_Exec_State_Request
// exec.IfDelay = false
// exec.Delay = Rand(RandMax)
exec.Timestamp = NowTimestamp() exec.Timestamp = NowTimestamp()
} }
...@@ -219,10 +219,19 @@ func (bak * MJbackup)init() { ...@@ -219,10 +219,19 @@ func (bak * MJbackup)init() {
bak.Status = Msg_Backup_Status_Start bak.Status = Msg_Backup_Status_Start
bak.Version = Version bak.Version = Version
} }
func (bak * MJbackup)Errorf(s string){
bak.Status = Msg_Backup_Status_Error // error
bak.Explain = "Backup Error: " + bak.Computername + " -> " + s
func GJerror(s * string) interface{}{
var err MJerror
err.init(s)
return err
} }
func (bak * MJbackup)PrintExplain(){ func (err * MJerror)init(s* string ){
PrintLog(bak.Username,bak.Status,bak.Explain) err.Username = User_name
err.Dept = User_dept
err.Timestamp = NowTimestamp()
err.Computername = User_computername
err.MsgType = Msg_Error
err.DataStr = *s
} }
\ No newline at end of file
...@@ -24,7 +24,9 @@ func SendServerExec(s string)[]byte{ ...@@ -24,7 +24,9 @@ func SendServerExec(s string)[]byte{
return SendServer(GJexec(s)) return SendServer(GJexec(s))
} }
func SendServerError(s string)[]byte{
return SendServer(GJerror(&s))
}
// send to server // send to server
func SendServer(v interface{})[]byte{ func SendServer(v interface{})[]byte{
return SendMsg(ADServerDaemon,v) return SendMsg(ADServerDaemon,v)
......
No preview for this file type
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"github.com/lxn/walk" "github.com/lxn/walk"
"AD-Control/public" "AD-Control/public"
) )
func userInit(){ func userInit() string{
public.Reg_Exist_item(public.HKCU,public.Reg_Path_achome) public.Reg_Exist_item(public.HKCU,public.Reg_Path_achome)
// 如果微盘的文件夹存在 // 如果微盘的文件夹存在
...@@ -19,6 +19,14 @@ func userInit(){ ...@@ -19,6 +19,14 @@ func userInit(){
} }
}() }()
} }
var icoDir =[]string {`AD-Control.ico`,`C:\Users\Public\Documents\AD-Control\AD-Control.ico`}
for _,i := range icoDir{
if public.Exist(i){
return i
}
}
public.SendServerError("no icon file")
return ""
} }
func menuInit(ni * walk.NotifyIcon){ func menuInit(ni * walk.NotifyIcon){
menuInitPower(ni) menuInitPower(ni)
...@@ -32,9 +40,9 @@ func menuInit(ni * walk.NotifyIcon){ ...@@ -32,9 +40,9 @@ func menuInit(ni * walk.NotifyIcon){
func main() { func main() {
// 用户初始化 // 用户初始化
userInit() icodir := userInit()
//if public.Daemon {public.Msg("版本错误")} public.PrintLog(icodir)
// 程序初始化 // 程序初始化
mw,err := walk.NewMainWindow() mw,err := walk.NewMainWindow()
...@@ -42,7 +50,7 @@ func main() { ...@@ -42,7 +50,7 @@ func main() {
public.PrintLog(err) public.PrintLog(err)
} }
icon, err := walk.Resources.Icon(`AD-Control.ico`) icon, err := walk.Resources.Icon(icodir)
if err != nil { if err != nil {
public.PrintLog(err) public.PrintLog(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment