2021-03-25 18:53:13 +03:00
|
|
|
module obj
|
2021-04-20 17:16:35 +03:00
|
|
|
|
2021-03-25 18:53:13 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
// read a file as single lines
|
|
|
|
pub fn read_lines_from_file(file_path string) []string {
|
2021-04-20 17:16:35 +03:00
|
|
|
mut path := ''
|
2021-03-25 18:53:13 +03:00
|
|
|
mut rows := []string{}
|
|
|
|
$if android {
|
2021-04-20 17:16:35 +03:00
|
|
|
path = 'models/' + file_path
|
2021-03-25 18:53:13 +03:00
|
|
|
bts := os.read_apk_asset(path) or {
|
2021-04-20 17:16:35 +03:00
|
|
|
eprintln('File [$path] NOT FOUND!')
|
2021-03-25 18:53:13 +03:00
|
|
|
return rows
|
|
|
|
}
|
|
|
|
rows = bts.bytestr().split_into_lines()
|
|
|
|
} $else {
|
2021-04-27 08:18:48 +03:00
|
|
|
path = os.resource_abs_path('assets/models/' + file_path)
|
2021-03-25 18:53:13 +03:00
|
|
|
rows = os.read_lines(path) or {
|
2021-04-27 08:18:48 +03:00
|
|
|
eprintln('File [$path] NOT FOUND! file_path: $file_path')
|
2021-03-25 18:53:13 +03:00
|
|
|
return rows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rows
|
|
|
|
}
|
|
|
|
|
2022-04-15 15:35:35 +03:00
|
|
|
// read a file as []u8
|
|
|
|
pub fn read_bytes_from_file(file_path string) []u8 {
|
2021-04-20 17:16:35 +03:00
|
|
|
mut path := ''
|
2022-04-15 15:35:35 +03:00
|
|
|
mut buffer := []u8{}
|
2021-03-25 18:53:13 +03:00
|
|
|
$if android {
|
2021-04-20 17:16:35 +03:00
|
|
|
path = 'models/' + file_path
|
2021-03-25 18:53:13 +03:00
|
|
|
buffer = os.read_apk_asset(path) or {
|
2021-04-20 17:16:35 +03:00
|
|
|
eprintln('Texure file: [$path] NOT FOUND!')
|
2021-03-25 18:53:13 +03:00
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
} $else {
|
2021-04-27 08:18:48 +03:00
|
|
|
path = os.resource_abs_path('assets/models/' + file_path)
|
2021-03-25 18:53:13 +03:00
|
|
|
buffer = os.read_bytes(path) or {
|
2021-04-20 17:16:35 +03:00
|
|
|
eprintln('Texure file: [$path] NOT FOUND!')
|
2021-03-25 18:53:13 +03:00
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buffer
|
2021-04-20 17:16:35 +03:00
|
|
|
}
|