Add warning when loading invalid file

This commit is contained in:
Tanasart 2023-12-09 16:49:02 +07:00
parent 79672e9765
commit 1539540928
4 changed files with 48 additions and 29 deletions

View file

@ -369,9 +369,9 @@ function gif_std_enum_getIndex() { return __enumIndex__; }
blocks = [];
static readBegin = function() { #region
if (self.i.readByte() != 71) throw string("Invalid header");
if (self.i.readByte() != 73) throw string("Invalid header");
if (self.i.readByte() != 70) throw string("Invalid header");
if (self.i.readByte() != 71) throw string("Gif loader: Invalid header");
if (self.i.readByte() != 73) throw string("Gif loader: Invalid header");
if (self.i.readByte() != 70) throw string("Gif loader: Invalid header");
var _gifVer = self.i.readString(3);
var _version = format_gif_Version_GIF89a;

View file

@ -1,4 +1,4 @@
function Node_create_Image(_x, _y, _group = noone) {
function Node_create_Image(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
path = get_open_filename("image|*.png;*.jpg", "");
@ -10,16 +10,16 @@ function Node_create_Image(_x, _y, _group = noone) {
node.inputs[| 0].setValue(path);
node.doUpdate();
return node;
}
} #endregion
function Node_create_Image_path(_x, _y, path) {
function Node_create_Image_path(_x, _y, path) { #region
if(!file_exists_empty(path)) return noone;
var node = new Node_Image(_x, _y, PANEL_GRAPH.getCurrentContext());
node.inputs[| 0].setValue(path);
node.doUpdate();
return node;
}
} #endregion
function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Image";
@ -43,7 +43,7 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
first_update = false;
on_drop_file = function(path) {
on_drop_file = function(path) { #region
inputs[| 0].setValue(path);
if(updatePaths(path)) {
@ -52,9 +52,9 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
}
return false;
}
} #endregion
function updatePaths(path) {
function updatePaths(path) { #region
path = try_get_path(path);
if(path == -1) return false;
@ -76,22 +76,27 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
first_update = true;
path_current = path;
if(spr == -1) {
noti_warning($"Image node: File not a valid image.");
return false;
}
return true;
}
return false;
}
} #endregion
insp1UpdateTooltip = __txt("Refresh");
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
static onInspector1Update = function() {
static onInspector1Update = function() { #region
var path = getInputData(0);
if(path == "") return;
updatePaths(path);
update();
}
} #endregion
static update = function(frame = CURRENT_FRAME) {
static update = function(frame = CURRENT_FRAME) { #region
var path = getInputData(0);
var pad = getInputData(1);
if(path == "") return;
@ -131,5 +136,5 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
_splice.inputs[| 3].setValue([ amo, 1 ]);
_splice.inspector1Update();
}
}
} #endregion
}

View file

@ -123,7 +123,14 @@ function Node_Image_Animated(_x, _y, _group = noone) : Node(_x, _y, _group) cons
case ".png" :
case ".jpg" :
case ".jpeg" :
array_push(spr, sprite_add(path, 1, false, false, 0, 0));
var _spr = sprite_add(path, 1, false, false, 0, 0);
if(_spr == -1) {
noti_warning($"Image node: File not a valid image.");
return false;
}
array_push(spr, _spr);
break;
}
}

View file

@ -1,4 +1,4 @@
function Node_create_Image_Sequence(_x, _y, _group = noone) {
function Node_create_Image_Sequence(_x, _y, _group = noone) { #region
var path = "";
if(!LOADING && !APPENDING && !CLONING) {
path = get_open_filenames_compat("image|*.png;*.jpg", "");
@ -11,14 +11,14 @@ function Node_create_Image_Sequence(_x, _y, _group = noone) {
node.inputs[| 0].setValue(paths);
node.doUpdate();
return node;
}
} #endregion
function Node_create_Image_Sequence_path(_x, _y, _path) {
function Node_create_Image_Sequence_path(_x, _y, _path) { #region
var node = new Node_Image_Sequence(_x, _y, PANEL_GRAPH.getCurrentContext());
node.inputs[| 0].setValue(_path);
node.doUpdate();
return node;
}
} #endregion
enum CANVAS_SIZE {
individual,
@ -63,7 +63,7 @@ function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) cons
path_loaded = [];
on_drop_file = function(path) {
on_drop_file = function(path) { #region
if(directory_exists(path)) {
with(dialogCall(o_dialog_drag_folder, WIN_W / 2, WIN_H / 2)) {
dir_paths = path;
@ -81,19 +81,19 @@ function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) cons
}
return false;
}
} #endregion
insp1UpdateTooltip = __txt("Refresh");
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
static onInspector1Update = function() {
static onInspector1Update = function() { #region
var path = getInputData(0);
if(path == "") return;
updatePaths(path);
update();
}
} #endregion
function updatePaths(paths) {
function updatePaths(paths) { #region
for(var i = 0; i < array_length(spr); i++) {
if(spr[i] && sprite_exists(spr[i]))
sprite_delete(spr[i]);
@ -113,7 +113,14 @@ function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) cons
case ".png" :
case ".jpg" :
case ".jpeg" :
array_push(spr, sprite_add(path, 1, false, false, 0, 0));
var _spr = sprite_add(path, 1, false, false, 0, 0);
if(_spr == -1) {
noti_warning($"Image node: File not a valid image.");
return false;
}
array_push(spr, _spr);
break;
}
}
@ -121,9 +128,9 @@ function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) cons
outputs[| 1].setValue(paths);
return true;
}
} #endregion
static update = function(frame = CURRENT_FRAME) {
static update = function(frame = CURRENT_FRAME) { #region
var path = getInputData(0);
if(path == "") return;
if(!is_array(path)) path = [ path ];
@ -219,5 +226,5 @@ function Node_Image_Sequence(_x, _y, _group = noone) : Node(_x, _y, _group) cons
}
outputs[| 0].setValue(surfs);
}
} #endregion
}