Skip to content
Permalink
Browse files

feat: Improve Sciter archive support.

Now you can call `SetResourceArchive` and its files will be resolved automatically.

refs #163.
  • Loading branch information...
pravic committed Aug 1, 2018
1 parent 93a8d4d commit 25d8ed42e0bb4c4acb742de9f148f6902d32ff41
@@ -1,42 +1,42 @@
<html> <html>


<head> <head>
<title>angles demo</title> <title>angles demo (packed in rice archive)</title>
<style> <style>
#gradient-rotated { #gradient-rotated {
position: absolute; position: absolute;
top: 40px; top: 40px;
left: 40px; left: 40px;
width: 300px; width: 300px;
height: 300px; height: 300px;
background: linear-gradient(45deg, red, yellow); background: linear-gradient(45deg, red, yellow);
background-image: -moz-linear-gradient(top left -45deg, red, yellow); // these guys use CCW direction in gradients for some reasons background-image: -moz-linear-gradient(top left -45deg, red, yellow); // these guys use CCW direction in gradients for some reasons
background-image: -webkit-linear-gradient(-45deg, red, yellow); background-image: -webkit-linear-gradient(-45deg, red, yellow);
} }
#rotated { #rotated {
position: absolute; position: absolute;
top: 40px; top: 40px;
left: 40px; left: 40px;
border: 1px dashed brown; border: 1px dashed brown;
width: 424px; width: 424px;
height: 50px; height: 50px;
transform: rotate(45deg); transform: rotate(45deg);
transform-origin: top left; transform-origin: top left;
-moz-transform: rotate(45deg); -moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg); -webkit-transform: rotate(45deg);
-moz-transform-origin: top left; -moz-transform-origin: top left;
-webkit-transform-origin: top left; -webkit-transform-origin: top left;
background: linear-gradient(left, red, yellow); background: linear-gradient(left, red, yellow);
background-image: -moz-linear-gradient(left, red, yellow); background-image: -moz-linear-gradient(left, red, yellow);
background-image: -webkit-linear-gradient(left, red, yellow); background-image: -webkit-linear-gradient(left, red, yellow);
} }
</style> </style>
</head> </head>


<body> <body>
<div id=gradient-rotated>gradient rotated +45&deg;</div> <div id=gradient-rotated>gradient rotated +45&deg;</div>
<div id=rotated>element rotated +45&deg;</div> <div id=rotated>element rotated +45&deg;</div>
</body> </body>


</html> </html>
@@ -38,7 +38,6 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
w.SetTitle("Example")
w.Show() w.Show()
w.Run() w.Run()
} }
@@ -0,0 +1,20 @@
package main

var resource_name []byte = []byte {
0x53,0x41,0x72,0x00,0x0c,0x00,0x00,0x00,0x73,0x00,0xff,0xff,0x01,0x00,0xff,0xff,0x69,0x00,0xff,0xff,0x02,0x00,0xff,0xff,0x6d,0x00,0xff,0xff,0x03,0x00,0xff,0xff,0x70,0x00,0xff,0xff,0x04,0x00,0xff,0xff,0x6c,
0x00,0xff,0xff,0x05,0x00,0xff,0xff,0x65,0x00,0xff,0xff,0x06,0x00,0xff,0xff,0x2e,0x00,0xff,0xff,0x07,0x00,0xff,0xff,0x68,0x00,0xff,0xff,0x08,0x00,0xff,0xff,0x74,0x00,0xff,0xff,0x09,0x00,0xff,0xff,0x6d,0x00,
0xff,0xff,0x0a,0x00,0xff,0xff,0x6c,0x00,0xff,0xff,0x0b,0x00,0xff,0xff,0x00,0x00,0xff,0xff,0x01,0x00,0xff,0xff,0x01,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x0e,0x02,0x00,0x00,0xf5,0x04,0x00,0x00,0x0e,0x3c,0x68,
0x74,0x6d,0x6c,0x3e,0x0d,0x0a,0x0d,0x0a,0x3c,0x68,0x65,0x61,0x64,0x20,0x09,0x00,0x20,0x20,0x00,0x13,0x3c,0x74,0x69,0x74,0x6c,0x65,0x3e,0x61,0x6e,0x67,0x6c,0x65,0x73,0x20,0x64,0x65,0x6d,0x6f,0x3c,0x2f,0x80,
0x12,0xa0,0x1f,0x02,0x73,0x74,0x79,0xe0,0x00,0x0c,0x12,0x23,0x67,0x72,0x61,0x64,0x69,0x65,0x6e,0x74,0x2d,0x72,0x6f,0x74,0x61,0x74,0x65,0x64,0x20,0x7b,0x80,0x18,0x40,0x00,0x12,0x70,0x6f,0x73,0x69,0x74,0x69,
0x6f,0x6e,0x3a,0x20,0x61,0x62,0x73,0x6f,0x6c,0x75,0x74,0x65,0x3b,0xe0,0x01,0x1c,0x08,0x74,0x6f,0x70,0x3a,0x20,0x34,0x30,0x70,0x78,0xe0,0x02,0x13,0x03,0x6c,0x65,0x66,0x74,0xe0,0x08,0x14,0x08,0x77,0x69,0x64,
0x74,0x68,0x3a,0x20,0x33,0x30,0xe0,0x05,0x16,0x04,0x68,0x65,0x69,0x67,0x68,0x20,0x2d,0xe0,0x07,0x17,0x12,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x3a,0x20,0x6c,0x69,0x6e,0x65,0x61,0x72,0x2d,0xc0,
0xa3,0x13,0x28,0x34,0x35,0x64,0x65,0x67,0x2c,0x20,0x72,0x65,0x64,0x2c,0x20,0x79,0x65,0x6c,0x6c,0x6f,0x77,0x29,0xe0,0x0c,0x39,0x0c,0x2d,0x69,0x6d,0x61,0x67,0x65,0x3a,0x20,0x2d,0x6d,0x6f,0x7a,0x2d,0xe0,0x07,
0x44,0x20,0xb8,0x60,0xa8,0x01,0x20,0x2d,0xe0,0x0b,0x4e,0x0f,0x20,0x2f,0x2f,0x20,0x74,0x68,0x65,0x73,0x65,0x20,0x67,0x75,0x79,0x73,0x20,0x75,0x20,0x08,0x08,0x43,0x43,0x57,0x20,0x64,0x69,0x72,0x65,0x63,0x41,
0x0b,0x03,0x20,0x69,0x6e,0x20,0xc0,0x4a,0x09,0x73,0x20,0x66,0x6f,0x72,0x20,0x73,0x6f,0x6d,0x65,0x20,0x43,0x04,0x61,0x73,0x6f,0x6e,0x73,0xe0,0x14,0x8c,0x05,0x77,0x65,0x62,0x6b,0x69,0x74,0xe0,0x08,0x8f,0xe0,
0x0c,0x86,0x80,0x48,0x00,0x7d,0x80,0x06,0x80,0x05,0x00,0x23,0xe1,0x50,0xa1,0x0f,0x62,0x6f,0x72,0x64,0x65,0x72,0x3a,0x20,0x31,0x70,0x78,0x20,0x64,0x61,0x73,0x68,0x20,0x63,0x04,0x62,0x72,0x6f,0x77,0x6e,0xe0,
0x02,0x22,0xa1,0xc4,0x02,0x34,0x32,0x34,0xe0,0x04,0x39,0xc1,0xc4,0x00,0x35,0xe0,0x05,0x50,0x04,0x74,0x72,0x61,0x6e,0x73,0x21,0x1b,0x02,0x6d,0x3a,0x20,0x80,0xb4,0x81,0xb9,0xc0,0xd6,0x40,0x00,0xe0,0x00,0x22,
0x05,0x2d,0x6f,0x72,0x69,0x67,0x69,0x20,0xc1,0x20,0xae,0x60,0x9e,0xe0,0x02,0x24,0x61,0xbf,0xe0,0x00,0x29,0xe0,0x11,0x4c,0xc1,0x5a,0xe0,0x1b,0x2a,0xe0,0x04,0x52,0xe0,0x14,0x7c,0xe0,0x07,0x54,0xe0,0x13,0x2c,
0xe1,0x01,0xee,0xe2,0x09,0xb5,0x40,0x2a,0xe1,0x0c,0xde,0x40,0x00,0xe0,0x01,0x38,0xe2,0x00,0x27,0x40,0xa1,0xe0,0x37,0x43,0xa0,0xbb,0xe0,0x20,0x46,0xa2,0x69,0x01,0x3c,0x2f,0xc4,0x1c,0x01,0x3c,0x2f,0xa4,0x52,
0x20,0x0a,0x03,0x62,0x6f,0x64,0x79,0x20,0x09,0x20,0x1f,0x08,0x20,0x3c,0x64,0x69,0x76,0x20,0x69,0x64,0x3d,0xc0,0x51,0xc4,0x36,0x00,0x3e,0xc0,0x10,0xa1,0x78,0x05,0x64,0x20,0x2b,0x34,0x35,0x26,0x21,0x7b,0x02,
0x3b,0x3c,0x2f,0x20,0x32,0xe0,0x06,0x3d,0xa0,0x23,0x04,0x3e,0x65,0x6c,0x65,0x6d,0xe0,0x13,0x33,0x01,0x3c,0x2f,0xa0,0x7a,0x40,0x0a,0x64,0xec,0x01,0x0d,0x0a,
}
@@ -0,0 +1,42 @@
<html>

<head>
<title>angles demo (packed in sciter archive)</title>
<style>
#gradient-rotated {
position: absolute;
top: 40px;
left: 40px;
width: 300px;
height: 300px;
background: linear-gradient(45deg, red, yellow);
background-image: -moz-linear-gradient(top left -45deg, red, yellow); // these guys use CCW direction in gradients for some reasons
background-image: -webkit-linear-gradient(-45deg, red, yellow);
}
#rotated {
position: absolute;
top: 40px;
left: 40px;
border: 1px dashed brown;
width: 424px;
height: 50px;
transform: rotate(45deg);
transform-origin: top left;
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform-origin: top left;
-webkit-transform-origin: top left;
background: linear-gradient(left, red, yellow);
background-image: -moz-linear-gradient(left, red, yellow);
background-image: -webkit-linear-gradient(left, red, yellow);
}
</style>
</head>

<body>
<div id=gradient-rotated>gradient rotated +45&deg;</div>
<div id=rotated>element rotated +45&deg;</div>
</body>

</html>
@@ -0,0 +1,37 @@
package main

import (
"log"
sciter "github.com/sciter-sdk/go-sciter"
window "github.com/sciter-sdk/go-sciter/window"
)

/*
A Sciter archive usage example.
To build it you need the `packfolder` tool from the Sciter SDK:
* convert resources from folder `res` to `res.go` via `packfolder res res.go -v resource_name -go`
* use it in your source code via `win.SetResourceArchive(resource_name)`
Now the resulting executable is completely stand-alone.
*/
func main() {
// As usual, create a sciter window.
w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN, nil)
if err != nil {
log.Fatal(err)
}

// 1. Handle resources via sciter archive loader.
// It handles URLs like `this://app/`.
w.SetResourceArchive(resource_name)

// 2. Load a packaged resource.
err = w.LoadFile("this://app/simple.html")
if err != nil {
log.Fatal(err)
}
w.Show()
w.Run()
}
@@ -35,7 +35,7 @@ func OnLoadData(s *sciter.Sciter) func(ld *sciter.ScnLoadData) int {
path = strings.Join(ps[1:], "/") path = strings.Join(ps[1:], "/")
} }
} else { } else {
// do not handle file:// or rice:// // // do not handle schemes other than file:// or rice://
return sciter.LOAD_OK return sciter.LOAD_OK
} }
// log.Println("rice loading:", path, "in box:", boxname) // log.Println("rice loading:", path, "in box:", boxname)
@@ -38,6 +38,7 @@ import "C"
import ( import (
"fmt" "fmt"
"log" "log"
"strings"
"runtime" "runtime"
"unsafe" "unsafe"
) )
@@ -449,7 +450,7 @@ func (s *Sciter) SetHomeURL(baseUrl string) (ok bool) {
return true return true
} }


// Open a data blob of the Sciter compressed archive. // Open data blob of the provided compressed Sciter archive.
func (s *Sciter) OpenArchive(data []byte) { func (s *Sciter) OpenArchive(data []byte) {
s.har = C.SciterOpenArchive((*C.BYTE)(&data[0]), C.UINT(len(data))) s.har = C.SciterOpenArchive((*C.BYTE)(&data[0]), C.UINT(len(data)))
} }
@@ -475,6 +476,44 @@ func (s *Sciter) CloseArchive() {
s.har = C.HSARCHIVE(nil) s.har = C.HSARCHIVE(nil)
} }


// Register `this://app/` URLs to be loaded from the given Sciter archive.
//
// Pack resources using `packfolder` tool:
//
// `$ packfolder res_folder res_packed.go -v resource_name -go`
//
// Usage:
//
//```
// win.SetResourceArchive(resource_name)
// win.LoadFile("this://app//index.htm")
//```
func (s *Sciter) SetResourceArchive(data []byte) {

// register `this://app/` schema
callback := &CallbackHandler{
OnLoadData: func(params *ScnLoadData) int {
if strings.HasPrefix(params.Uri(), "this://app/") {
// load resource starting with our schema
url := params.Uri()[11:]
fileData := s.GetArchiveItem(url)
if fileData != nil {
// use loaded resource
s.DataReady(url, fileData)
} else {
// failed to load
log.Println("error: failed to load " + params.Uri())
// but fallback to Sciter anyway
}
}
return LOAD_OK
},
}

s.OpenArchive(data)
s.SetCallback(callback)
}

// #if defined(OSX) // #if defined(OSX)
// HWINDOW SciterCreateNSView ( LPRECT frame ) ;//{ return SAPI()->SciterCreateNSView ( frame ); } // HWINDOW SciterCreateNSView ( LPRECT frame ) ;//{ return SAPI()->SciterCreateNSView ( frame ); }
// #endif // #endif

0 comments on commit 25d8ed4

Please sign in to comment.
You can’t perform that action at this time.