下載安裝 go-sciter 包git
go get github.com/oskca/sciter
修改 sciter-x-api.c ,添加以下代碼:github
HSARCHIVE SCAPI SciterOpenArchive (LPCBYTE archiveData, UINT archiveDataLength) { return SAPI(NULL)->SciterOpenArchive (archiveData,archiveDataLength); } BOOL SCAPI SciterGetArchiveItem (HSARCHIVE harc, LPCWSTR path, LPCBYTE* pdata, UINT* pdataLength){return SAPI(NULL)->SciterGetArchiveItem (harc,path,pdata,pdataLength); }
修改 sciter.go,添加以下代碼:api
func (s *Sciter) OpenArchive(data []byte) { s.har = C.SciterOpenArchive((*C.BYTE)(&data[0]), C.UINT(len(data))) } func (s *Sciter) GetArchiveItem(uri string) []byte { var pv uintptr = 0 var length uint = 0 pBytes := (*C.LPCBYTE)(unsafe.Pointer(&pv)) pnBytes := (*C.UINT)(unsafe.Pointer(&length)) r := C.SciterGetArchiveItem(s.har, StringToWcharPtr(uri), pBytes, pnBytes) if r == 0 { return nil } ret := []byte{} for i := 0; i < int(length); i++ { b := *(*byte)(unsafe.Pointer(pv + uintptr(i))) ret = append(ret, b) } return ret }
用sciter自帶工具打包 資源:app
packfolder.exe res resources.cpp -v "res" //packfolder.exe 「資源文件夾」,「輸出cpp文件名」 -v "變量名"
拷貝cpp內容存爲res.go:工具
// res.go package main var res = []byte{
編寫main.goui
package main import ( "log" "strings" "github.com/oskca/sciter" "github.com/oskca/sciter/window" ) func OnLoadData(s *sciter.Sciter) func(ld *sciter.ScnLoadData) int { return func(ld *sciter.ScnLoadData) int { uri := ld.Uri() log.Println("loading:", uri) if strings.HasPrefix(uri, "this://app/") { path := uri[11:] log.Println("path:", path) data := s.GetArchiveItem(path) if data == nil { log.Println("GetArchiveItem:False") return sciter.LOAD_OK } s.DataReady(uri, data) } return sciter.LOAD_OK } } func newHandler(s *sciter.Sciter) *sciter.CallbackHandler { return &sciter.CallbackHandler{ OnLoadData: OnLoadData(s), } } func main() { w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN, sciter.NewRect(300, 300, 600, 400)) if err != nil { log.Fatal("Create Window Error: ", err) } w.SetCallback(newHandler(w.Sciter)) w.OpenArchive(res) w.LoadFile("app/main.htm") w.Show() w.Run() }