Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- v007a2 241120b
- */
- $dat_file='SGD_sample.dat';
- $dat_file='ROMSMINE/_SGD304/Arcade4.dat';
- //==========get SGD.ini paths :=======================
- // Define the path to your .ini file
- $iniFilePath = 'ROMSMINE/_SGD304/sgd.ini';
- // Define the new prefix you want to set
- $newPrefix = 'NEW_PREFIX_FOR_PATH'; // Change this to what you need
- // Initialize an array to hold the GameDir paths
- $gameDirs = [];
- // Open the file for reading
- if ($fileHandle = fopen($iniFilePath, 'r')) {
- // Read each line of the file
- while (($line = fgets($fileHandle)) !== false) {
- // Trim whitespace from the line
- $line = trim($line);
- // Check if the line starts with 'GameDir'
- if (strpos($line, 'GameDir') === 0) {
- // Extract the path after the '=' sign
- $parts = explode('=', $line);
- if (count($parts) === 2) {
- $path = trim($parts[1]);
- // Adjust path with the new prefix
- ///$newPath = preg_replace('/^E:\\OPT\\SPECTRUM\\ROMSMINE\\/', $newPrefix . '\\', $path);
- // Store the modified path
- $gameDirs[]=$path;
- //$gameDirs[] = $newPath;
- }
- }
- }
- // Close the file handle
- fclose($fileHandle);
- } else {
- echo "Unable to open the file.";
- }
- // Output the modified GameDir paths
- foreach ($gameDirs as $gameDir) {
- //echo $gameDir . PHP_EOL."<BR>";
- }
- //==END of========get SGD.ini paths :=======================
- // Database field definitions
- $fieldDefinitions = [
- 'Name' => ['start' => 1, 'length' => 36],
- 'Year' => ['start' => 38, 'length' => 4],
- 'Publisher' => ['start' => 43, 'length' => 36],
- 'Memory' => ['start' => 80, 'length' => 3],
- 'PC-Name' => ['start' => 94, 'length' => 12],
- 'Type' => ['start' => 107, 'length' => 7],
- 'PathIndex' => ['start' => 115, 'length' => 3],
- 'FileSize' => ['start' => 119, 'length' => 7],
- 'Orig_screen' => ['start' => 127, 'length' => 1],
- 'Origin' => ['start' => 129, 'length' => 1],
- 'FloppyId' => ['start' => 131, 'length' => 4],
- 'Emul_override' => ['start' => 136, 'length' => 2],
- 'AYSound' => ['start' => 139, 'length' => 1],
- 'MultiLoad' => ['start' => 141, 'length' => 1],
- 'Language' => ['start' => 143, 'length' => 3],
- 'Score' => ['start' => 147, 'length' => 3],
- 'Author' => ['start' => 151, 'length' => 100],
- 'Joysticks' => ['start' => 88, 'length' => 5],
- '#OfPlayers' => ['start' => 84, 'length' => 1],
- 'Together' => ['start' => 86, 'length' => 1],
- ];
- // Helper function to extract a field from a line
- function getField($line, $field) {
- global $fieldDefinitions;
- $start = $fieldDefinitions[$field]['start'];
- $length = $fieldDefinitions[$field]['length'];
- return trim(substr($line, $start - 1, $length));
- }
- // Read the file and build the games list
- $file = fopen($dat_file, 'r');
- $games = [];
- while (($line = fgets($file)) !== false) {
- $game = [];
- foreach ($fieldDefinitions as $field => $definition) {
- $game[$field] = getField($line, $field);
- }
- $games[] = $game;
- }
- fclose($file);
- // Handle game update via POST
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $gameData = $_POST;
- $lineIndex = $gameData['lineIndex']; // Index of the game to update
- unset($gameData['lineIndex']); // Remove the lineIndex from POST data
- // Update the game data logic here
- $fileLines = file($dat_file);
- $lineToUpdate = $fileLines[$lineIndex];
- foreach ($fieldDefinitions as $field => $definition) {
- $start = $definition['start'] - 1;
- $length = $definition['length'];
- $lineToUpdate = substr_replace($lineToUpdate, str_pad($gameData[$field], $length), $start, $length);
- }
- $fileLines[$lineIndex] = $lineToUpdate;
- file_put_contents($dat_file, implode('', $fileLines));
- // Return the updated game as well
- $updatedGame = [];
- foreach ($fieldDefinitions as $field => $definition) {
- $updatedGame[$field] = $gameData[$field];
- }
- echo json_encode(['status' => 'success', 'updatedGame' => $updatedGame, 'lineIndex' => $lineIndex]);
- exit;
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Game Database</title>
- <style>
- body {
- display: flex;
- margin: 0;
- #font-family: Arial, sans-serif;
- background-color: lightgrey;
- font-family: "Courier New", Courier, monospace;
- }
- #left-panel, #right-panel {
- padding: 20px;
- overflow-y: auto;
- }
- #left-panel {
- width: 60%;
- border-right: 1px solid #ccc;
- background-color: lightgrey;
- }
- #right-panel {
- #flex: 1;
- position: fixed;
- top: 10px; /* Distance from the top */
- right: 10px; /* Distance from the right */
- background-color: gainsboro; /* Semi-transparent background */
- border: 1px solid #ccc;
- padding: 10px;
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
- z-index: 1000; /* Make sure it appears above other content */
- max-height: calc(100vh - 20px); /* max height minus top and bottom offsets */
- overflow-y: auto; /* Enable vertical scrolling when needed */
- }
- .game-item {
- padding: 10px;
- border-bottom: 1px solid #ddd;
- cursor: pointer;
- }
- .game-item:hover {
- background-color: #eee;
- }
- .game-item.active {
- background-color: #dcdcdc;
- }
- .form-field {
- margin-bottom: 10px;
- }
- .form-field label {
- font-weight: bold;
- }
- .form-field input, .form-field textarea {
- padding: 8px;
- border: 1px solid #ddd;
- border-radius: 4px;
- background-color: Silver;
- }
- </style>
- <script>
- document.addEventListener('DOMContentLoaded', () => {
- const gameItems = document.querySelectorAll('.game-item');
- const form = document.getElementById('game-form');
- const fields = <?php echo json_encode(array_keys($fieldDefinitions)); ?>;
- // Attach click handlers to game items
- gameItems.forEach(item => {
- item.addEventListener('click', () => {
- // Remove active class from all items
- document.querySelectorAll('.game-item').forEach(i => i.classList.remove('active'));
- item.classList.add('active');
- // Load game data into form
- const gameData = JSON.parse(item.dataset.game);
- fields.forEach(field => {
- const input = form.querySelector(`[name="${field}"]`);
- if (input) input.value = gameData[field];
- });
- form.querySelector('[name="lineIndex"]').value = item.dataset.index; // Store the index for the form submission
- });
- });
- // Handle form submission
- form.addEventListener('submit', (e) => {
- e.preventDefault();
- const formData = new FormData(form);
- fetch('', {
- method: 'POST',
- body: formData
- })
- .then(response => response.json())
- .then(data => {
- if (data.status === 'success') {
- // Update the left panel with the updated game
- const updatedGame = data.updatedGame;
- const lineIndex = data.lineIndex;
- const updatedGameItem = document.querySelector(`.game-item[data-index="${lineIndex}"]`);
- if (updatedGameItem) {
- updatedGameItem.dataset.game = JSON.stringify(updatedGame);
- updatedGameItem.querySelector('strong').textContent = updatedGame.Name;
- //updatedGameItem.querySelector('small').textContent = updatedGame['PC-Name'];
- }
- alert('Game updated successfully!');
- }
- });
- });
- });
- </script>
- </head>
- <body>
- <div id="left-panel">
- <h3>Game List</h3>
- <?php foreach ($games as $index => $game): ?>
- <div class="game-item" data-game='<?php echo json_encode($game); ?>' data-index="<?php echo $index; ?>">
- <strong><?php echo htmlspecialchars($game['Name']); ?></strong><br>
- <small><?php //echo htmlspecialchars($game['PC-Name']); ?></small>
- </div>
- <?php endforeach; ?>
- </div>
- <div id="right-panel">
- <h3>Game Details</h3>
- <form id="game-form">
- <input type="hidden" name="lineIndex" value="">
- <button type="submit">Save</button>
- <div class="form-field">
- <label for="Name">Name:</label>
- <input type="text" id="Name" name="Name" value="" maxlength="36" size="36" />
- </div>
- <div class="form-field">
- <label for="Publisher">Publisher:</label>
- <input type="text" id="Publisher" name="Publisher" value="" maxlength="36" size="36" />
- </div>
- <div class="form-field">
- <label for="Author">Author:</label>
- <input type="text" id="Author" name="Author" value="" maxlength="50" size="50" />
- </div>
- <div class="form-field"></div>
- <div class="form-field">
- <label for="Year">Year:</label>
- <input type="text" id="Year" name="Year" value="" maxlength="4" size="4" />
- <label for="Memory">Memory:</label>
- <input type="text" id="Memory" name="Memory" value="" maxlength="3" size="3" />
- </div>
- <div class="form-field">
- <label for="#OfPlayers">#OfPlayers:</label>
- <input type="text" id="#OfPlayers" name="#OfPlayers" value="" maxlength="1" size="1" />
- <label for="Together">Together:</label>
- <input type="text" id="Together" name="Together" value="" maxlength="1" size="1" />
- <label for="Score">Score:</label>
- <input type="text" id="Score" name="Score" value="" maxlength="3" size="3" />
- </div>
- <div class="form-field">
- <label for="PC-Name">PC-Name:</label>
- <input type="text" id="PC-Name" name="PC-Name" value="" maxlength="12" size="12" />
- <label for="Type">Type:</label>
- <input type="text" id="Type" name="Type" value="" maxlength="7" size="7" />
- </div>
- <div class="form-field">
- <label for="Joysticks">Joysticks:</label>
- <input type="text" id="Joysticks" name="Joysticks" value="" maxlength="5" size="5" />
- </div>
- <div class="form-field">
- <label for="Orig_screen">Orig_screen:</label>
- <input type="text" id="Orig_screen" name="Orig_screen" value="" maxlength="1" size="1" />
- <label for="Origin">Origin:</label>
- <input type="text" id="Origin" name="Origin" value="" maxlength="1" size="1" />
- </div>
- <div class="form-field">
- <label for="AYSound">AYSound:</label>
- <input type="text" id="AYSound" name="AYSound" value="" maxlength="1" size="1" />
- <label for="MultiLoad">MultiLoad:</label>
- <input type="text" id="MultiLoad" name="MultiLoad" value="" maxlength="1" size="1" />
- <label for="FloppyId">FloppyId:</label>
- <input type="text" id="FloppyId" name="FloppyId" value="" maxlength="4" size="4" />
- </div>
- <div class="form-field">
- <label for="Language">Language:</label>
- <input type="text" id="Language" name="Language" value="" maxlength="3" size="3" />
- <label for="Emul_override">Emul_override:</label>
- <input type="text" id="Emul_override" name="Emul_override" value="" maxlength="2" size="2" />
- </div>
- <div class="form-field">
- <label for="PathIndex">PathIndex:</label>
- <input type="text" id="PathIndex" name="PathIndex" value="" maxlength="3" size="3" />
- <label for="FileSize">FileSize:</label>
- <input type="text" id="FileSize" name="FileSize" value="" maxlength="7" size="7" />
- </div>
- <div class="form-field"></div>
- <button type="submit">Save</button>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement