From 95a1cde04c6229d89e0e9278c3021b50f52bfbe5 Mon Sep 17 00:00:00 2001 From: cuu Date: Sun, 30 Sep 2018 00:40:05 +0800 Subject: [PATCH] about --- Menu/GameShell/10_Settings/About/about.go | 75 ++++++++++++++++++++++- sysgo/UI/util_funcs.go | 56 ++++++++++++++++- 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/Menu/GameShell/10_Settings/About/about.go b/Menu/GameShell/10_Settings/About/about.go index c4b1eb7..6c46f73 100644 --- a/Menu/GameShell/10_Settings/About/about.go +++ b/Menu/GameShell/10_Settings/About/about.go @@ -92,7 +92,7 @@ type AboutPage struct { } func NewAboutPage() *AboutPage { - p := &HelloWorldPage{} + p := &AboutPage{} p.FootMsg = [5]string{"Nav.","","","Back",""} @@ -136,7 +136,21 @@ func (self *AboutPage) Uname() { func (self *AboutPage) CpuMhz() { - + + lines, err := readLines("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq") + UI.ShowErr(err) + + mhz ,_ := strconv.ParseInt(lines[0], 10, 0)) + + mhz_float := float64(mhz)/1000.0 + + out := make(map[string]string) + out["key"] = "cpuscalemhz" + out["label"]="CPU Mhz:" + out["value"] = strconv.FormatFloat(mhz_float, 'f', 2, 64) + + self.AList["cpuscalemhz"] = out + } func (self *AboutPage) CpuInfo() { @@ -144,11 +158,66 @@ func (self *AboutPage) CpuInfo() { } func (self *AboutPage) MemInfo() { - + lines, err := readLines("/proc/meminfo") + UI.ShowErr(err) + + for _,line := range lines { + if strings.HasPrefix(line,"MemTotal") { + parts := strings.Split(line,":") + kb := strings.Replace(parts[1],"KB","",-1) + kb = strings.TrimSpace(kb) + kb_int,_ := strconv.ParseInt(kb,10,0) + + kb_float := float64(kb_int)/1000.0 + memory := make(map[string]string) + memory["key"] = "memory" + memory["label"] = "Memory:" + memory["value"] = strconv.FormatFloat(kb_float,'f',2,64) + " MB" + self.AList["memory"] = memory + break + } + } } func (self *AboutPage) GenList() { + self.MyList = nil + self.MyList = make([]*InfoPageListItem,0) + + start_x := 0 + start_y := 10 + last_height := 0 + + for i,u := range ( []string{"processor","armcores","cpuscalemhz","features","memory","uname"} ) { + if val, ok := self.AList[u]; ok { + + li := NewInfoPageListItem() + li.Parent = self + li.PosX = start_x + li.PosY = start_y + last_height + li.Width = UI.Width + li.Fonts["normal"] = self.ListFontObj + li.Fonts["small"] = UI.Fonts["varela12"] + + if self.AList[u]["label"] != "" { + li.Init( self.AList[u]["label"] ) + }else { + li.Init( self.AList[u]["key"]) + } + + li.Flag = val["key"] + li.SetSmallText(val["value"]) + + self.MyList = append(self.MyList,li) + } + } } + +func (self *AboutPage) Init() { + + + + +} diff --git a/sysgo/UI/util_funcs.go b/sysgo/UI/util_funcs.go index 2c6a2a1..9f6023d 100644 --- a/sysgo/UI/util_funcs.go +++ b/sysgo/UI/util_funcs.go @@ -6,7 +6,9 @@ import ( "path/filepath" "strings" "fmt" - + "bufio" + "bytes" + "github.com/cuu/gogame/display" "github.com/cuu/LauncherGo/sysgo" @@ -118,3 +120,55 @@ func ReplaceSuffix(orig_file_str string, new_ext string) string { func SwapAndShow() { display.Flip() } + +func ReadLines(path string)(lines [] string,err error){ + var ( + file *os.File + part [] byte + prefix bool + ) + + if file, err = os.Open(path); err != nil { + return + } + + reader := bufio.NewReader(file) + buffer := bytes.NewBuffer(make([]byte,1024)) + + for { + if part, prefix, err = reader.ReadLine();err != nil { + break + } + buffer.Write(part) + if !prefix { + lines = append(lines,buffer.String()) + buffer.Reset() + } + } + if err == io.EOF { + err = nil + } + return +} + +func WriteLines(lines [] string,path string)(err error){ + var file *os.File + + if file,err = os.Create(path); err != nil{ + return + } + + defer file.Close() + + for _,elem := range lines { + _,err := file.WriteString(strings.TrimSpace(elem)+"\n") + if err != nil { + fmt.Println(err) + break + } + } + return +} + + +