Select Git revision
kolloquiums.js
kolloquiums.js 17.66 KiB
const { Router } = require('express')
var fs = require("fs");
var exec = require('child_process').exec;
var extract = require('extract-zip')
const router = Router();
const path = require('path');
const {resolve} = require("path");
const replace = require('replace-in-file');
const kolloquiumDirectory = '../Kolloquiums'
const modDirectory = 'C:/Users/Nick/Documents/UnrealEngine/Projects/KolloquiumVR/Mods'
const pakDirectory = 'C:/Users/Nick/Documents/UnrealPackagedGames/KolloquiumVR/WindowsNoEditor/KolloquiumVR/Mods'
const editorFile = 'C:/Users/Nick/Documents/UnrealEngine/Projects/KolloquiumVR/Saved/Config/Windows/Editor.ini'
function getDirectories(path) {
// check if directory exists
if (fs.existsSync(path)) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
} else {
console.log('Directory not found.');
return []
}
}
function isEmpty(checkString) {
return (!checkString || checkString.trim().length == 0)
}
function removeDangerousSymbols(fname) {
// https://stackoverflow.com/a/31976060
// https://gist.github.com/doctaphred/d01d05291546186941e1b7ddc02034d3
// removed check for empty: if is empty, nothing should be done with the string by the other api functions
const fname_original = fname;
// resolve multi-line, whitespace trimming
fname = fname.split(/[\r\n]/).map(s => s.trim()).filter(s => s.length).join(" ");
// forbidden characters
// (after multi-line, because new-line-chars are themselves forbidden characters)
fname = fname.replaceAll(/[<>.:"\/\\\|?*\x00-\x1F]/g, '');
// advanced trim
fname = fname.replace(/\.$/, "");
// remove blank spaces because it breaks paths
// TODO: Make it so blank spaces do not breka paths anymore
fname = fname.replaceAll(' ', '_');
// forbidden filenames
if (fname.match(/^(CON|PRN|AUX|NUL|COM1|COM2|COM3|COM4|COM5|COM6|COM7|COM8|COM9|LPT1|LPT2|LPT3|LPT4|LPT5|LPT6|LPT7|LPT8|LPT9)(\..+)?$/)) {
fname = `_${fname}`;
}
return fname;
}
fs.mkdir(kolloquiumDirectory,function(err) {
if (err && err.code === "EEXIST") {
console.log('Kolloquiums Directory already existed')
}
else if (err) {
return console.error(err);
}
else {
console.log("Directory created successfully");
}
});