Repository navigation
Expand file tree
/
Copy pathplatform_utils.py
More file actions
68 lines (58 loc) · 2.59 KB
/
Copy pathplatform_utils.py
File metadata and controls
68 lines (58 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# platform_utils.py - Cross-platform utilities for RetroDB
# ================================================================================
# Centralized platform detection and OS-specific helpers.
# Used across the application to ensure Linux/Windows/macOS compatibility.
# ================================================================================
import sys
import socket
# =============================================================================
# OS DETECTION
# =============================================================================
IS_WINDOWS = sys.platform == 'win32'
IS_MACOS = sys.platform == 'darwin'
IS_LINUX = sys.platform.startswith('linux')
PLATFORM_NAME = 'Windows' if IS_WINDOWS else ('macOS' if IS_MACOS else 'Linux')
# =============================================================================
# NETWORK UTILITIES
# =============================================================================
def get_local_ip():
"""Get the local network IP address (works on all platforms)"""
try:
# Connect to a public DNS to determine local IP (no data is sent)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(2)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
s.close()
return ip
except Exception:
return '127.0.0.1'
# =============================================================================
# TOOL DETECTION
# =============================================================================
def get_tool_install_instructions():
"""Get platform-specific tool installation instructions"""
if IS_LINUX:
return {
'unzip': 'sudo apt install unzip',
'7z': 'sudo apt install p7zip-full',
'unrar': 'sudo apt install unrar',
'chdman': 'sudo apt install mame-tools',
'all': 'sudo apt install p7zip-full unrar mame-tools',
}
elif IS_MACOS:
return {
'unzip': 'Built-in on macOS',
'7z': 'brew install p7zip',
'unrar': 'brew install unrar',
'chdman': 'brew install rom-tools (or build from MAME source)',
'all': 'brew install p7zip unrar rom-tools',
}
else: # Windows
return {
'unzip': 'Built-in on Windows (PowerShell) or install 7-Zip',
'7z': 'Download 7-Zip from https://www.7-zip.org/',
'unrar': 'Download WinRAR from https://www.win-rar.com/',
'chdman': 'Download MAME from https://www.mamedev.org/ (includes chdman)',
'all': 'Install 7-Zip, WinRAR, and MAME (for chdman)',
}