Skip to content

Commit b4c6cc6

Browse files
committed
Make model method at the top
1 parent 1780c4e commit b4c6cc6

1 file changed

Lines changed: 45 additions & 45 deletions

File tree

lib.ring

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ class SysInfo {
2828
OSDeleteFile(psTempScript)
2929
}
3030

31+
// Method to get device model
32+
func model() {
33+
// Get model info from modelInfo
34+
modelInfo = modelInfo()
35+
36+
// Return the model info
37+
return modelInfo
38+
}
39+
3140
// Method to get the hostname
3241
func hostname() {
3342
// Execute command to get hostname
@@ -437,17 +446,45 @@ class SysInfo {
437446
return networkInfo
438447
}
439448

440-
// Method to get device model
441-
func model() {
442-
// Get model info from modelInfo
443-
modelInfo = modelInfo()
449+
private
444450

445-
// Return the model info
446-
return modelInfo
447-
}
451+
// Helper function to get device model
452+
func modelInfo() {
453+
// Initialize model
454+
model = "Unknown"
448455

449-
private
456+
// Check if the OS is Windows
457+
if (isWindows()) {
458+
// Get the device model from winSysInfo List
459+
if (!isNull(winSysInfo[:model])) {
460+
model = winSysInfo[:model]
461+
}
462+
elseif (isLinux()) // If the OS is Linux
463+
// Define a list of dmi file paths
464+
dmiPaths = [
465+
"/sys/class/dmi/id/product_name",
466+
"/sys/class/dmi/id/product_version",
467+
"/sys/class/dmi/id/board_name"
468+
]
469+
470+
// Loop through each dmi path to get the model
471+
for path in dmiPaths {
472+
if (fexists(path)) {
473+
fileContent = trim(readFile(path))
474+
if (!isNull(fileContent) and len(fileContent) > 0) {
475+
model = substr(fileContent, nl, "")
476+
return model
477+
}
478+
}
479+
}
480+
elseif (isFreeBSD()) // If the OS is FreeBSD
481+
model = trim(systemCmd("sysctl -n hw.model"))
482+
}
450483

484+
// Return the model
485+
return model
486+
}
487+
451488
// Helper function to get osInfo
452489
func osInfo() {
453490
// Initialize the OS info list
@@ -955,43 +992,6 @@ class SysInfo {
955992
return networkInfo
956993
}
957994

958-
// Helper function to get device model
959-
func modelInfo() {
960-
// Initialize model
961-
model = "Unknown"
962-
963-
// Check if the OS is Windows
964-
if (isWindows()) {
965-
// Get the device model from winSysInfo List
966-
if (!isNull(winSysInfo[:model])) {
967-
model = winSysInfo[:model]
968-
}
969-
elseif (isLinux()) // If the OS is Linux
970-
// Define a list of dmi file paths
971-
dmiPaths = [
972-
"/sys/class/dmi/id/product_name",
973-
"/sys/class/dmi/id/product_version",
974-
"/sys/class/dmi/id/board_name"
975-
]
976-
977-
// Loop through each dmi path to get the model
978-
for path in dmiPaths {
979-
if (fexists(path)) {
980-
fileContent = trim(readFile(path))
981-
if (!isNull(fileContent) and len(fileContent) > 0) {
982-
model = substr(fileContent, nl, "")
983-
return model
984-
}
985-
}
986-
}
987-
elseif (isFreeBSD()) // If the OS is FreeBSD
988-
model = trim(systemCmd("sysctl -n hw.model"))
989-
}
990-
991-
// Return the model
992-
return model
993-
}
994-
995995
// Helper function to parse ip addr output (For Linux)
996996
func parseIpAddr(output) {
997997
// Initialize interfaces list

0 commit comments

Comments
 (0)