fix unwritten subdirectories from the extension

This commit is contained in:
idk
2020-04-03 15:34:08 -04:00
parent 2a0217f9f1
commit b281603315
3 changed files with 93 additions and 25 deletions

View File

@ -1,11 +1,14 @@
VERSION=0.0.01
all:
all: gen
GOOS=windows go build -o i2pchromium.exe
GOOS=darwin go build -o i2pchromium-darwin
GOOS=linux go build -o i2pchromium
gen:
go run -tags generate gen.go
release:
gothub release -p -u eyedeekay -r "I2P-Configuration-for-Chromium" -t $(VERSION) -n "Launchers" -d "A self-configuring launcher for I2P Browsing with Chromium"; true
gothub upload -R -u eyedeekay -r "I2P-Configuration-for-Chromium" -t $(VERSION) -n "i2pchromium.exe" -f "i2pchromium.exe"

View File

@ -13,11 +13,11 @@ var assets = map[string][]byte{}
var FS = &fs{}
type fs struct{}
type fs struct {}
func (fs *fs) Open(name string) (http.File, error) {
if name == "/" {
return fs, nil
return fs, nil;
}
b, ok := assets[name]
if !ok {
@ -26,16 +26,16 @@ func (fs *fs) Open(name string) (http.File, error) {
return &file{name: name, size: len(b), Reader: bytes.NewReader(b)}, nil
}
func (fs *fs) Close() error { return nil }
func (fs *fs) Read(p []byte) (int, error) { return 0, nil }
func (fs *fs) Close() error { return nil }
func (fs *fs) Read(p []byte) (int, error) { return 0, nil }
func (fs *fs) Seek(offset int64, whence int) (int64, error) { return 0, nil }
func (fs *fs) Stat() (os.FileInfo, error) { return fs, nil }
func (fs *fs) Name() string { return "/" }
func (fs *fs) Size() int64 { return 0 }
func (fs *fs) Mode() os.FileMode { return 0755 }
func (fs *fs) ModTime() time.Time { return time.Time{} }
func (fs *fs) IsDir() bool { return true }
func (fs *fs) Sys() interface{} { return nil }
func (fs *fs) Stat() (os.FileInfo, error) { return fs, nil }
func (fs *fs) Name() string { return "/" }
func (fs *fs) Size() int64 { return 0 }
func (fs *fs) Mode() os.FileMode { return 0755}
func (fs *fs) ModTime() time.Time{ return time.Time{} }
func (fs *fs) IsDir() bool { return true }
func (fs *fs) Sys() interface{} { return nil }
func (fs *fs) Readdir(count int) ([]os.FileInfo, error) {
files := []os.FileInfo{}
for name, data := range assets {
@ -47,18 +47,18 @@ func (fs *fs) Readdir(count int) ([]os.FileInfo, error) {
type file struct {
name string
size int
*bytes.Reader
*bytes.Reader
}
func (f *file) Close() error { return nil }
func (f *file) Close() error { return nil }
func (f *file) Readdir(count int) ([]os.FileInfo, error) { return nil, errors.New("not supported") }
func (f *file) Stat() (os.FileInfo, error) { return f, nil }
func (f *file) Name() string { return f.name }
func (f *file) Size() int64 { return int64(f.size) }
func (f *file) Mode() os.FileMode { return 0644 }
func (f *file) ModTime() time.Time { return time.Time{} }
func (f *file) IsDir() bool { return false }
func (f *file) Sys() interface{} { return nil }
func (f *file) Stat() (os.FileInfo, error) { return f, nil }
func (f *file) Name() string { return f.name }
func (f *file) Size() int64 { return int64(f.size) }
func (f *file) Mode() os.FileMode { return 0644 }
func (f *file) ModTime() time.Time{ return time.Time{} }
func (f *file) IsDir() bool { return false }
func (f *file) Sys() interface{} { return nil }
func init() {
assets["/.gitignore"] = []byte{0x52, 0x45, 0x41, 0x44, 0x4d, 0x45, 0x2e, 0x6d, 0x64, 0x2e, 0x61, 0x73, 0x63, 0x0a, 0x0a}

73
main.go
View File

@ -3,8 +3,11 @@
package main
import (
"bytes"
"io"
"io/ioutil"
"log"
"net/http"
"os"
. "github.com/eyedeekay/go-ccw"
@ -31,19 +34,81 @@ var ARGS = []string{
"--disable-file-system",
}
func main() {
if embedded, err := FS.Readdir(0); err != nil {
func writeSubDirectory(fs http.File) {
log.Println("writing subdirectory")
name, err := fs.Stat()
if err != nil {
log.Fatal(err)
}
if embedded, err := fs.Readdir(0); err != nil {
log.Println("Extension error, embedded extension not read.")
} else {
if _, err := os.Stat("i2pchrome.js"); os.IsNotExist(err) {
os.MkdirAll("i2pchrome.js", FS.Mode())
os.MkdirAll("i2pchrome.js/"+name.Name(), FS.Mode())
for _, val := range embedded {
ioutil.WriteFile("i2pchrome.js"+val.Name(), val.Sys().([]byte), val.Mode())
file, err := FS.Open(val.Name()) //
if err != nil {
log.Fatal(err.Error())
}
sys := bytes.NewBuffer(nil)
if _, err := io.Copy(sys, file); err != nil {
log.Fatal(err.Error())
}
ioutil.WriteFile("i2pchrome.js/"+name.Name()+"/"+val.Name(), sys.Bytes(), val.Mode())
}
} else {
log.Println("i2pchrome plugin already found")
}
}
}
func writeExtension(val os.FileInfo, system http.FileSystem) {
if len(val.Name()) > 3 {
if val.IsDir() {
os.MkdirAll("i2pchrome.js/"+val.Name(), FS.Mode())
file, err := FS.Open(val.Name()) //
if err != nil {
log.Fatal(err.Error())
}
writeSubDirectory(file)
} else {
log.Println("Writing file to extension", val.Name())
file, err := FS.Open(val.Name()) //
if err != nil {
log.Fatal(err.Error())
}
sys := bytes.NewBuffer(nil)
if _, err := io.Copy(sys, file); err != nil {
log.Fatal(err.Error())
}
if err := ioutil.WriteFile("i2pchrome.js/"+val.Name(), sys.Bytes(), val.Mode()); err != nil {
log.Fatal(err.Error())
}
}
} else {
log.Println("+i2pchrome.js/"+val.Name()+"'", "ignored", "contents", val.Sys())
}
}
func writeProfile(system http.FileSystem) {
if embedded, err := FS.Readdir(0); err != nil {
log.Println("Extension error, embedded extension not read.")
} else {
if _, err := os.Stat("i2pchrome.js"); os.IsNotExist(err) {
os.MkdirAll("i2pchrome.js/icons", FS.Mode())
os.MkdirAll("i2pchrome.js/options", FS.Mode())
os.MkdirAll("i2pchrome.js/_locales/en", FS.Mode())
for _, val := range embedded {
writeExtension(val, FS)
}
} else {
log.Println("i2pchrome plugin already found")
}
}
}
func main() {
writeProfile(FS)
CHROMIUM, ERROR = SecureExtendedChromium("i2pchromium-browser", false, EXTENSIONS, EXTENSIONHASHES, ARGS...)
if ERROR != nil {
log.Fatal(ERROR)