mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Fix: Add parameter to file reading actions to remove CR characters from files (#4352)
⚠️ If you had encountered an issue linked to this and changed your events to fix it, you might need to update your project and set this new parameter to "No"
This commit is contained in:
@@ -203,6 +203,18 @@ module.exports = {
|
||||
'',
|
||||
true
|
||||
)
|
||||
.addParameter(
|
||||
'yesorno',
|
||||
_('Normalize the file content (recommended)'),
|
||||
'',
|
||||
true
|
||||
)
|
||||
.setParameterLongDescription(
|
||||
_(
|
||||
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
|
||||
)
|
||||
)
|
||||
.setDefaultValue('yes')
|
||||
.getCodeExtraInformation()
|
||||
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
|
||||
.setFunctionName('gdjs.fileSystem.loadStringFromFileAsync');
|
||||
@@ -229,6 +241,18 @@ module.exports = {
|
||||
'',
|
||||
true
|
||||
)
|
||||
.addParameter(
|
||||
'yesorno',
|
||||
_('Normalize the file content (recommended)'),
|
||||
'',
|
||||
true
|
||||
)
|
||||
.setParameterLongDescription(
|
||||
_(
|
||||
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
|
||||
)
|
||||
)
|
||||
.setDefaultValue('yes')
|
||||
.getCodeExtraInformation()
|
||||
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
|
||||
.setFunctionName('gdjs.fileSystem.loadStringFromFile');
|
||||
@@ -255,6 +279,18 @@ module.exports = {
|
||||
'',
|
||||
true
|
||||
)
|
||||
.addParameter(
|
||||
'yesorno',
|
||||
_('Normalize the file content (recommended)'),
|
||||
'',
|
||||
true
|
||||
)
|
||||
.setParameterLongDescription(
|
||||
_(
|
||||
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
|
||||
)
|
||||
)
|
||||
.setDefaultValue('yes')
|
||||
.getCodeExtraInformation()
|
||||
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
|
||||
.setFunctionName('gdjs.fileSystem.loadVariableFromJSONFile');
|
||||
@@ -281,6 +317,18 @@ module.exports = {
|
||||
'',
|
||||
true
|
||||
)
|
||||
.addParameter(
|
||||
'yesorno',
|
||||
_('Normalize the file content (recommended)'),
|
||||
'',
|
||||
true
|
||||
)
|
||||
.setParameterLongDescription(
|
||||
_(
|
||||
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
|
||||
)
|
||||
)
|
||||
.setDefaultValue('yes')
|
||||
.getCodeExtraInformation()
|
||||
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
|
||||
.setFunctionName('gdjs.fileSystem.loadVariableFromJSONFileAsync');
|
||||
|
@@ -338,11 +338,13 @@ namespace gdjs {
|
||||
* @param stringVar Variable where to store the content
|
||||
* @param loadPath Path to the file
|
||||
* @param resultVar The variable where to store the result of the operation
|
||||
* @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files
|
||||
*/
|
||||
export const loadStringFromFile = function (
|
||||
stringVar: gdjs.Variable,
|
||||
loadPath: string,
|
||||
resultVar: gdjs.Variable
|
||||
resultVar: gdjs.Variable,
|
||||
removeCRCharacters: boolean
|
||||
) {
|
||||
const fileSystem = gdjs.fileSystem._getFs();
|
||||
let result = 'error';
|
||||
@@ -350,7 +352,9 @@ namespace gdjs {
|
||||
try {
|
||||
const data = fileSystem.readFileSync(loadPath, 'utf8');
|
||||
if (data) {
|
||||
stringVar.setString(data);
|
||||
stringVar.setString(
|
||||
removeCRCharacters ? data.replace(/\r/g, '') : data
|
||||
);
|
||||
result = 'ok';
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -368,11 +372,13 @@ namespace gdjs {
|
||||
* @param variable Variable to store the variable
|
||||
* @param loadPath Path to the file
|
||||
* @param resultVar The variable where to store the result of the operation
|
||||
* @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files
|
||||
*/
|
||||
export const loadVariableFromJSONFile = function (
|
||||
variable: gdjs.Variable,
|
||||
loadPath: string,
|
||||
resultVar: gdjs.Variable
|
||||
resultVar: gdjs.Variable,
|
||||
removeCRCharacters: boolean
|
||||
) {
|
||||
const fileSystem = gdjs.fileSystem._getFs();
|
||||
let result = 'error';
|
||||
@@ -380,7 +386,9 @@ namespace gdjs {
|
||||
try {
|
||||
const data = fileSystem.readFileSync(loadPath, 'utf8');
|
||||
if (data) {
|
||||
variable.fromJSON(data);
|
||||
variable.fromJSON(
|
||||
removeCRCharacters ? data.replace(/\r/g, '') : data
|
||||
);
|
||||
result = 'ok';
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -400,17 +408,21 @@ namespace gdjs {
|
||||
* @param variable Variable to store the variable
|
||||
* @param loadPath Path to the file
|
||||
* @param resultVar The variable where to store the result of the operation
|
||||
* @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files
|
||||
*/
|
||||
export const loadVariableFromJSONFileAsync = function (
|
||||
variable: gdjs.Variable,
|
||||
loadPath: string,
|
||||
resultVar: gdjs.Variable
|
||||
resultVar: gdjs.Variable,
|
||||
removeCRCharacters: boolean
|
||||
) {
|
||||
const fileSystem = gdjs.fileSystem._getFs();
|
||||
if (fileSystem) {
|
||||
fileSystem.readFile(loadPath, 'utf8', (err, data) => {
|
||||
if (data) {
|
||||
variable.fromJSON(data);
|
||||
variable.fromJSON(
|
||||
removeCRCharacters ? data.replace(/\r/g, '') : data
|
||||
);
|
||||
resultVar.setString('ok');
|
||||
}
|
||||
if (err) {
|
||||
@@ -431,17 +443,21 @@ namespace gdjs {
|
||||
* @param stringVar Variable where to store the content
|
||||
* @param loadPath Path to the file
|
||||
* @param resultVar The variable where to store the result of the operation
|
||||
* @param removeCRCharacters If true, will remove \r characters usually added by Windows when editing files
|
||||
*/
|
||||
export const loadStringFromFileAsync = function (
|
||||
stringVar: gdjs.Variable,
|
||||
loadPath: string,
|
||||
resultVar: gdjs.Variable
|
||||
resultVar: gdjs.Variable,
|
||||
removeCRCharacters: boolean
|
||||
) {
|
||||
const fileSystem = gdjs.fileSystem._getFs();
|
||||
if (fileSystem) {
|
||||
fileSystem.readFile(loadPath, 'utf8', (err, data) => {
|
||||
if (data) {
|
||||
stringVar.setString(data);
|
||||
stringVar.setString(
|
||||
removeCRCharacters ? data.replace(/\r/g, '') : data
|
||||
);
|
||||
resultVar.setString('ok');
|
||||
}
|
||||
if (err) {
|
||||
|
Reference in New Issue
Block a user