Skip to content

Commit f2289f6

Browse files
committed
fix: all clients installation, ready for publishing.
1 parent 2599bed commit f2289f6

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/scripts/script.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,7 @@ document.addEventListener('DOMContentLoaded', () => {
658658
try {
659659
statusText.textContent = 'Checking version...';
660660
const versionResponse = await axios.get('https://cactus.denchik.top/info');
661-
const versionData = versionResponse.data;
662-
const latestVersion = versionData.version;
661+
const latestVersion = versionResponse.data.version;
663662

664663
statusText.textContent = 'Downloading...';
665664
progressBar.style.width = '0%';
@@ -854,27 +853,18 @@ document.addEventListener('DOMContentLoaded', () => {
854853
progressBar.style.width = '40%';
855854

856855
statusText.textContent = 'Extracting...';
857-
const extractPath = installPath;
858856
if (process.platform === 'linux') {
859857
const { execSync } = require('child_process');
860858
try {
861-
execSync(`tar -xJf "${tempZipPath}" -C "${extractPath}"`);
859+
execSync(`tar -zxf "${tempZipPath}" -C "${installPath}"`);
862860
progressBar.style.width = '70%';
863861
} catch (err) {
864-
throw new Error(`Failed to extract tar.xz: ${err.message}`);
862+
throw new Error(`Failed to extract tar.gz: ${err.message}`);
865863
}
866864
} else {
867865
const zip = new AdmZip(tempZipPath);
868-
const totalEntries = zip.getEntries().length;
869-
let extractedCount = 0;
870-
zip.extractAllToAsync(extractPath, true, (err) => {
871-
if (err) throw err;
872-
extractedCount++;
873-
const extractProgress = 40 + Math.round((extractedCount / totalEntries) * 30);
874-
progressBar.style.width = `${extractProgress}%`;
875-
});
876866
await new Promise((resolve, reject) => {
877-
zip.extractAllToAsync(extractPath, true, (err) => {
867+
zip.extractAllToAsync(installPath, true, (err) => {
878868
if (err) return reject(err);
879869
resolve();
880870
});
@@ -883,12 +873,24 @@ document.addEventListener('DOMContentLoaded', () => {
883873
}
884874

885875
statusText.textContent = 'Renaming Folder...';
886-
const zip = new AdmZip(tempZipPath);
887-
const extractedFolder = zip.getEntries()[0].entryName.split('/')[0];
888-
const oldFolderPath = path.join(extractPath, extractedFolder);
889-
if (fs.existsSync(clientPath)) fs.rmSync(clientPath, { recursive: true });
890-
fs.renameSync(oldFolderPath, clientPath);
891-
progressBar.style.width = '90%';
876+
let extractedFolder;
877+
if (process.platform === 'linux') {
878+
const extractedFiles = fs.readdirSync(installPath).filter(file =>
879+
fs.statSync(path.join(installPath, file)).isDirectory()
880+
);
881+
extractedFolder = extractedFiles.find(file => file !== gameData.clientName && file.includes('teeworlds')) || 'teeworlds-0.7.5-linux_x86_64';
882+
console.log('Extracted folders for Teeworlds:', extractedFiles);
883+
} else {
884+
extractedFolder = new AdmZip(tempZipPath).getEntries()[0].entryName.split('/')[0];
885+
}
886+
const oldFolderPath = path.join(installPath, extractedFolder);
887+
if (fs.existsSync(clientPath)) fs.rmSync(clientPath, { recursive: true });
888+
if (fs.existsSync(oldFolderPath)) {
889+
fs.renameSync(oldFolderPath, clientPath);
890+
} else {
891+
throw new Error(`Extracted folder not found at ${oldFolderPath}. Available folders: ${fs.readdirSync(installPath).join(', ')}`);
892+
}
893+
progressBar.style.width = '90%';
892894

893895
statusText.textContent = 'Writing Version...';
894896
fs.writeFileSync(path.join(clientPath, 'clientver.txt'), version);

0 commit comments

Comments
 (0)