152
152
foreach (string arg in args[1:unclaimed_args + 1]) {
153
153
// We set a message, that later is informed to the user
154
154
// in a dialog if something noteworthy happens.
157
157
var file = File.new_for_commandline_arg (arg);
159
if (!file.query_exists ())
160
FileUtils.set_contents (file.get_path (), "");
159
if (!file.query_exists ()) {
161
FileUtils.set_contents (file.get_path (), "");
163
// We list some common errors for quick feedback
164
if (e is FileError.ACCES) {
165
string reason = _("Maybe you do not have the necessary permissions.");
166
msg = _("File \"%s\" cannot be created.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
167
} else if (e is FileError.NOENT) {
168
string reason = _("Maybe the file path provided is not valid.");
169
msg = _("File \"%s\" cannot be created.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
170
} else if (e is FileError.ROFS) {
171
string reason = _("The location is read-only.");
172
msg = _("File \"%s\" cannot be created.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
174
// Otherwise we simple use the error notification from glib
162
180
var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null);
163
if (info.get_file_type () == FileType.REGULAR)
181
if (info.get_file_type () == FileType.REGULAR
182
|| info.get_file_type () == FileType.SYMBOLIC_LINK) {
166
message = _("File \"%s\" cannot be opened.\nIt's not a regular file.").printf ("<b>%s</b>".printf (file.get_uri ()));
184
} else if (info.get_file_type () == FileType.MOUNTABLE){
185
string reason = _("Is a mountable location.");
186
msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
187
} else if (info.get_file_type () == FileType.DIRECTORY ){
188
string reason = _("Is a directory.");
189
msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
190
} else if (info.get_file_type () == FileType.SPECIAL ){
191
string reason = _("Is a \"special\" file such as a socket,\n fifo, block device, or character device.");
192
msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
194
string reason = _("Is a \"unknown\" file type.");
195
msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
168
198
} catch (Error e) {
169
// In case we failed create the file
170
if (e is FileError.PERM || e is FileError.ACCES) {
171
var file = File.new_for_commandline_arg (arg);
172
message = _("File \"%s\" cannot be created.\nMaybe you do not have the necessary permissions.").printf ("<b>%s</b>".printf (file.get_uri ()));
175
199
warning (e.message);
178
202
// Notify the user that something happened.
179
if (message.length > 0) {
203
if (msg.length > 0) {
180
204
var parent_window = get_last_window () as Gtk.Window;
181
205
var dialog = new Gtk.MessageDialog.with_markup (parent_window,
182
206
Gtk.DialogFlags.MODAL,
183
207
Gtk.MessageType.ERROR,
184
208
Gtk.ButtonsType.CLOSE,
187
211
dialog.destroy ();