Files
go-i2pbrowser/unembed.go

56 lines
1.8 KiB
Go
Raw Permalink Normal View History

2022-09-25 17:57:09 -04:00
package goi2pbrowser
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"github.com/artdarek/go-unzip/pkg/unzip"
)
func existsAlready(profileDir string) bool {
if _, err := os.Stat(filepath.Join(profileDir, "user.js")); err == nil {
return true
}
return false
}
2022-09-25 23:56:48 -04:00
// UnpackBase unpacks a "Strict" mode profile into the "profileDir" and returns the
// path to the profile and possibly, an error if something goes wrong. If everything
// works, the error will be nil
2022-09-25 18:24:48 -04:00
func UnpackBase(profileDir string) (string, error) {
2022-10-04 03:08:28 -04:00
log.Println(profileDir, "exists already")
2022-09-25 17:57:09 -04:00
os.MkdirAll(filepath.Dir(profileDir), 0755)
zipFile := filepath.Join(filepath.Dir(profileDir), "i2p.firefox.base.profile.zip")
2022-09-26 00:21:19 -04:00
err := ioutil.WriteFile(zipFile, BaseProfile, 0644)
2022-09-25 17:57:09 -04:00
if err != nil {
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.base.profile"), err
2022-09-25 17:57:09 -04:00
}
uz := unzip.New()
_, err = uz.Extract(zipFile, profileDir)
if err != nil {
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.base.profile"), err
2022-09-25 17:57:09 -04:00
}
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.base.profile"), nil
2022-09-25 17:57:09 -04:00
}
2022-09-25 23:56:48 -04:00
// UnpackUsability unpacks a "Usability" mode profile into the "profileDir" and returns the
// path to the profile and possibly, an error if something goes wrong. If everything
// works, the error will be nil
2022-09-25 18:24:48 -04:00
func UnpackUsability(profileDir string) (string, error) {
2022-10-04 03:08:28 -04:00
log.Println(profileDir, "exists already")
2022-09-25 17:57:09 -04:00
os.MkdirAll(filepath.Dir(profileDir), 0755)
zipFile := filepath.Join(filepath.Dir(profileDir), "i2p.firefox.usability.profile.zip")
2022-09-26 00:21:19 -04:00
err := ioutil.WriteFile(zipFile, UsabilityProfile, 0644)
2022-09-25 17:57:09 -04:00
if err != nil {
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.usability.profile"), err
2022-09-25 17:57:09 -04:00
}
uz := unzip.New()
_, err = uz.Extract(zipFile, profileDir)
if err != nil {
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.usability.profile"), err
2022-09-25 17:57:09 -04:00
}
2022-09-25 18:24:48 -04:00
return filepath.Join(profileDir, "i2p.firefox.usability.profile"), nil
2022-09-25 17:57:09 -04:00
}