1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.FileT; 26 27 public import gio.AppInfo; 28 public import gio.AppInfoIF; 29 public import gio.AsyncResultIF; 30 public import gio.Cancellable; 31 public import gio.File; 32 public import gio.FileAttributeInfoList; 33 public import gio.FileEnumerator; 34 public import gio.FileIF; 35 public import gio.FileIOStream; 36 public import gio.FileInfo; 37 public import gio.FileInputStream; 38 public import gio.FileMonitor; 39 public import gio.FileOutputStream; 40 public import gio.Mount; 41 public import gio.MountIF; 42 public import gio.MountOperation; 43 public import glib.Bytes; 44 public import glib.ConstructionException; 45 public import glib.ErrorG; 46 public import glib.GException; 47 public import glib.Str; 48 public import gobject.ObjectG; 49 public import gtkc.gio; 50 public import gtkc.giotypes; 51 52 53 /** 54 * #GFile is a high level abstraction for manipulating files on a 55 * virtual file system. #GFiles are lightweight, immutable objects 56 * that do no I/O upon creation. It is necessary to understand that 57 * #GFile objects do not represent files, merely an identifier for a 58 * file. All file content I/O is implemented as streaming operations 59 * (see #GInputStream and #GOutputStream). 60 * 61 * To construct a #GFile, you can use: 62 * - g_file_new_for_path() if you have a path. 63 * - g_file_new_for_uri() if you have a URI. 64 * - g_file_new_for_commandline_arg() for a command line argument. 65 * - g_file_new_tmp() to create a temporary file from a template. 66 * - g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name(). 67 * 68 * One way to think of a #GFile is as an abstraction of a pathname. For 69 * normal files the system pathname is what is stored internally, but as 70 * #GFiles are extensible it could also be something else that corresponds 71 * to a pathname in a userspace implementation of a filesystem. 72 * 73 * #GFiles make up hierarchies of directories and files that correspond to 74 * the files on a filesystem. You can move through the file system with 75 * #GFile using g_file_get_parent() to get an identifier for the parent 76 * directory, g_file_get_child() to get a child within a directory, 77 * g_file_resolve_relative_path() to resolve a relative path between two 78 * #GFiles. There can be multiple hierarchies, so you may not end up at 79 * the same root if you repeatedly call g_file_get_parent() on two different 80 * files. 81 * 82 * All #GFiles have a basename (get with g_file_get_basename()). These names 83 * are byte strings that are used to identify the file on the filesystem 84 * (relative to its parent directory) and there is no guarantees that they 85 * have any particular charset encoding or even make any sense at all. If 86 * you want to use filenames in a user interface you should use the display 87 * name that you can get by requesting the 88 * %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info(). 89 * This is guaranteed to be in UTF-8 and can be used in a user interface. 90 * But always store the real basename or the #GFile to use to actually 91 * access the file, because there is no way to go from a display name to 92 * the actual name. 93 * 94 * Using #GFile as an identifier has the same weaknesses as using a path 95 * in that there may be multiple aliases for the same file. For instance, 96 * hard or soft links may cause two different #GFiles to refer to the same 97 * file. Other possible causes for aliases are: case insensitive filesystems, 98 * short and long names on FAT/NTFS, or bind mounts in Linux. If you want to 99 * check if two #GFiles point to the same file you can query for the 100 * %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial 101 * canonicalization of pathnames passed in, so that trivial differences in 102 * the path string used at creation (duplicated slashes, slash at end of 103 * path, "." or ".." path segments, etc) does not create different #GFiles. 104 * 105 * Many #GFile operations have both synchronous and asynchronous versions 106 * to suit your application. Asynchronous versions of synchronous functions 107 * simply have _async() appended to their function names. The asynchronous 108 * I/O functions call a #GAsyncReadyCallback which is then used to finalize 109 * the operation, producing a GAsyncResult which is then passed to the 110 * function's matching _finish() operation. 111 * 112 * It is highly recommended to use asynchronous calls when running within a 113 * shared main loop, such as in the main thread of an application. This avoids 114 * I/O operations blocking other sources on the main loop from being dispatched. 115 * Synchronous I/O operations should be performed from worker threads. See the 116 * [introduction to asynchronous programming section][async-programming] for 117 * more. 118 * 119 * Some #GFile operations almost always take a noticeable amount of time, and 120 * so do not have synchronous analogs. Notable cases include: 121 * - g_file_mount_mountable() to mount a mountable file. 122 * - g_file_unmount_mountable_with_operation() to unmount a mountable file. 123 * - g_file_eject_mountable_with_operation() to eject a mountable file. 124 * 125 * ## Entity Tags # {#gfile-etag} 126 * 127 * One notable feature of #GFiles are entity tags, or "etags" for 128 * short. Entity tags are somewhat like a more abstract version of the 129 * traditional mtime, and can be used to quickly determine if the file 130 * has been modified from the version on the file system. See the 131 * HTTP 1.1 132 * [specification](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) 133 * for HTTP Etag headers, which are a very similar concept. 134 */ 135 public template FileT(TStruct) 136 { 137 /** Get the main Gtk struct */ 138 public GFile* getFileStruct() 139 { 140 return cast(GFile*)getStruct(); 141 } 142 143 144 /** 145 * Constructs a #GFile with the given @parse_name (i.e. something 146 * given by g_file_get_parse_name()). This operation never fails, 147 * but the returned object might not support any I/O operation if 148 * the @parse_name cannot be parsed. 149 * 150 * Params: 151 * parseName = a file name or path to be parsed 152 * 153 * Return: a new #GFile. 154 */ 155 public static FileIF parseName(string parseName) 156 { 157 auto p = g_file_parse_name(Str.toStringz(parseName)); 158 159 if(p is null) 160 { 161 return null; 162 } 163 164 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 165 } 166 167 /** 168 * Gets an output stream for appending data to the file. 169 * If the file doesn't already exist it is created. 170 * 171 * By default files created are generally readable by everyone, 172 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file 173 * will be made readable only to the current user, to the level that 174 * is supported on the target filesystem. 175 * 176 * If @cancellable is not %NULL, then the operation can be cancelled 177 * by triggering the cancellable object from another thread. If the 178 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 179 * returned. 180 * 181 * Some file systems don't allow all file names, and may return an 182 * %G_IO_ERROR_INVALID_FILENAME error. If the file is a directory the 183 * %G_IO_ERROR_IS_DIRECTORY error will be returned. Other errors are 184 * possible too, and depend on what kind of filesystem the file is on. 185 * 186 * Params: 187 * flags = a set of #GFileCreateFlags 188 * cancellable = optional #GCancellable object, 189 * %NULL to ignore 190 * 191 * Return: a #GFileOutputStream, or %NULL on error. 192 * Free the returned object with g_object_unref(). 193 * 194 * Throws: GException on failure. 195 */ 196 public FileOutputStream appendTo(GFileCreateFlags flags, Cancellable cancellable) 197 { 198 GError* err = null; 199 200 auto p = g_file_append_to(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 201 202 if (err !is null) 203 { 204 throw new GException( new ErrorG(err) ); 205 } 206 207 if(p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 213 } 214 215 /** 216 * Asynchronously opens @file for appending. 217 * 218 * For more details, see g_file_append_to() which is 219 * the synchronous version of this call. 220 * 221 * When the operation is finished, @callback will be called. 222 * You can then call g_file_append_to_finish() to get the result 223 * of the operation. 224 * 225 * Params: 226 * flags = a set of #GFileCreateFlags 227 * ioPriority = the [I/O priority][io-priority] of the request 228 * cancellable = optional #GCancellable object, 229 * %NULL to ignore 230 * callback = a #GAsyncReadyCallback to call 231 * when the request is satisfied 232 * userData = the data to pass to callback function 233 */ 234 public void appendToAsync(GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 235 { 236 g_file_append_to_async(getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 237 } 238 239 /** 240 * Finishes an asynchronous file append operation started with 241 * g_file_append_to_async(). 242 * 243 * Params: 244 * res = #GAsyncResult 245 * 246 * Return: a valid #GFileOutputStream 247 * or %NULL on error. 248 * Free the returned object with g_object_unref(). 249 * 250 * Throws: GException on failure. 251 */ 252 public FileOutputStream appendToFinish(AsyncResultIF res) 253 { 254 GError* err = null; 255 256 auto p = g_file_append_to_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 257 258 if (err !is null) 259 { 260 throw new GException( new ErrorG(err) ); 261 } 262 263 if(p is null) 264 { 265 return null; 266 } 267 268 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 269 } 270 271 /** 272 * Copies the file @source to the location specified by @destination. 273 * Can not handle recursive copies of directories. 274 * 275 * If the flag #G_FILE_COPY_OVERWRITE is specified an already 276 * existing @destination file is overwritten. 277 * 278 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks 279 * will be copied as symlinks, otherwise the target of the 280 * @source symlink will be copied. 281 * 282 * If @cancellable is not %NULL, then the operation can be cancelled by 283 * triggering the cancellable object from another thread. If the operation 284 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 285 * 286 * If @progress_callback is not %NULL, then the operation can be monitored 287 * by setting this to a #GFileProgressCallback function. 288 * @progress_callback_data will be passed to this function. It is guaranteed 289 * that this callback will be called after all data has been transferred with 290 * the total number of bytes copied during the operation. 291 * 292 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND error 293 * is returned, independent on the status of the @destination. 294 * 295 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, then 296 * the error %G_IO_ERROR_EXISTS is returned. 297 * 298 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY 299 * error is returned. If trying to overwrite a directory with a directory the 300 * %G_IO_ERROR_WOULD_MERGE error is returned. 301 * 302 * If the source is a directory and the target does not exist, or 303 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then the 304 * %G_IO_ERROR_WOULD_RECURSE error is returned. 305 * 306 * If you are interested in copying the #GFile object itself (not the on-disk 307 * file), see g_file_dup(). 308 * 309 * Params: 310 * destination = destination #GFile 311 * flags = set of #GFileCopyFlags 312 * cancellable = optional #GCancellable object, 313 * %NULL to ignore 314 * progressCallback = function to callback with 315 * progress information, or %NULL if progress information is not needed 316 * progressCallbackData = user data to pass to @progress_callback 317 * 318 * Return: %TRUE on success, %FALSE otherwise. 319 * 320 * Throws: GException on failure. 321 */ 322 public bool copy(FileIF destination, GFileCopyFlags flags, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData) 323 { 324 GError* err = null; 325 326 auto p = g_file_copy(getFileStruct(), (destination is null) ? null : destination.getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, &err) != 0; 327 328 if (err !is null) 329 { 330 throw new GException( new ErrorG(err) ); 331 } 332 333 return p; 334 } 335 336 /** 337 * Copies the file @source to the location specified by @destination 338 * asynchronously. For details of the behaviour, see g_file_copy(). 339 * 340 * If @progress_callback is not %NULL, then that function that will be called 341 * just like in g_file_copy(). The callback will run in the default main context 342 * of the thread calling g_file_copy_async() — the same context as @callback is 343 * run in. 344 * 345 * When the operation is finished, @callback will be called. You can then call 346 * g_file_copy_finish() to get the result of the operation. 347 * 348 * Params: 349 * destination = destination #GFile 350 * flags = set of #GFileCopyFlags 351 * ioPriority = the [I/O priority][io-priority] of the request 352 * cancellable = optional #GCancellable object, 353 * %NULL to ignore 354 * progressCallback = function to callback with progress 355 * information, or %NULL if progress information is not needed 356 * progressCallbackData = user data to pass to @progress_callback 357 * callback = a #GAsyncReadyCallback to call when the request is satisfied 358 * userData = the data to pass to callback function 359 */ 360 public void copyAsync(FileIF destination, GFileCopyFlags flags, int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GAsyncReadyCallback callback, void* userData) 361 { 362 g_file_copy_async(getFileStruct(), (destination is null) ? null : destination.getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, callback, userData); 363 } 364 365 /** 366 * Copies the file attributes from @source to @destination. 367 * 368 * Normally only a subset of the file attributes are copied, 369 * those that are copies in a normal file copy operation 370 * (which for instance does not include e.g. owner). However 371 * if #G_FILE_COPY_ALL_METADATA is specified in @flags, then 372 * all the metadata that is possible to copy is copied. This 373 * is useful when implementing move by copy + delete source. 374 * 375 * Params: 376 * destination = a #GFile to copy attributes to 377 * flags = a set of #GFileCopyFlags 378 * cancellable = optional #GCancellable object, 379 * %NULL to ignore 380 * 381 * Return: %TRUE if the attributes were copied successfully, 382 * %FALSE otherwise. 383 * 384 * Throws: GException on failure. 385 */ 386 public bool copyAttributes(FileIF destination, GFileCopyFlags flags, Cancellable cancellable) 387 { 388 GError* err = null; 389 390 auto p = g_file_copy_attributes(getFileStruct(), (destination is null) ? null : destination.getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 391 392 if (err !is null) 393 { 394 throw new GException( new ErrorG(err) ); 395 } 396 397 return p; 398 } 399 400 /** 401 * Finishes copying the file started with g_file_copy_async(). 402 * 403 * Params: 404 * res = a #GAsyncResult 405 * 406 * Return: a %TRUE on success, %FALSE on error. 407 * 408 * Throws: GException on failure. 409 */ 410 public bool copyFinish(AsyncResultIF res) 411 { 412 GError* err = null; 413 414 auto p = g_file_copy_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err) != 0; 415 416 if (err !is null) 417 { 418 throw new GException( new ErrorG(err) ); 419 } 420 421 return p; 422 } 423 424 /** 425 * Creates a new file and returns an output stream for writing to it. 426 * The file must not already exist. 427 * 428 * By default files created are generally readable by everyone, 429 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file 430 * will be made readable only to the current user, to the level 431 * that is supported on the target filesystem. 432 * 433 * If @cancellable is not %NULL, then the operation can be cancelled 434 * by triggering the cancellable object from another thread. If the 435 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 436 * returned. 437 * 438 * If a file or directory with this name already exists the 439 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't 440 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME 441 * error, and if the name is to long %G_IO_ERROR_FILENAME_TOO_LONG will 442 * be returned. Other errors are possible too, and depend on what kind 443 * of filesystem the file is on. 444 * 445 * Params: 446 * flags = a set of #GFileCreateFlags 447 * cancellable = optional #GCancellable object, 448 * %NULL to ignore 449 * 450 * Return: a #GFileOutputStream for the newly created 451 * file, or %NULL on error. 452 * Free the returned object with g_object_unref(). 453 * 454 * Throws: GException on failure. 455 */ 456 public FileOutputStream create(GFileCreateFlags flags, Cancellable cancellable) 457 { 458 GError* err = null; 459 460 auto p = g_file_create(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 461 462 if (err !is null) 463 { 464 throw new GException( new ErrorG(err) ); 465 } 466 467 if(p is null) 468 { 469 return null; 470 } 471 472 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 473 } 474 475 /** 476 * Asynchronously creates a new file and returns an output stream 477 * for writing to it. The file must not already exist. 478 * 479 * For more details, see g_file_create() which is 480 * the synchronous version of this call. 481 * 482 * When the operation is finished, @callback will be called. 483 * You can then call g_file_create_finish() to get the result 484 * of the operation. 485 * 486 * Params: 487 * flags = a set of #GFileCreateFlags 488 * ioPriority = the [I/O priority][io-priority] of the request 489 * cancellable = optional #GCancellable object, 490 * %NULL to ignore 491 * callback = a #GAsyncReadyCallback to call 492 * when the request is satisfied 493 * userData = the data to pass to callback function 494 */ 495 public void createAsync(GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 496 { 497 g_file_create_async(getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 498 } 499 500 /** 501 * Finishes an asynchronous file create operation started with 502 * g_file_create_async(). 503 * 504 * Params: 505 * res = a #GAsyncResult 506 * 507 * Return: a #GFileOutputStream or %NULL on error. 508 * Free the returned object with g_object_unref(). 509 * 510 * Throws: GException on failure. 511 */ 512 public FileOutputStream createFinish(AsyncResultIF res) 513 { 514 GError* err = null; 515 516 auto p = g_file_create_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 517 518 if (err !is null) 519 { 520 throw new GException( new ErrorG(err) ); 521 } 522 523 if(p is null) 524 { 525 return null; 526 } 527 528 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 529 } 530 531 /** 532 * Creates a new file and returns a stream for reading and 533 * writing to it. The file must not already exist. 534 * 535 * By default files created are generally readable by everyone, 536 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file 537 * will be made readable only to the current user, to the level 538 * that is supported on the target filesystem. 539 * 540 * If @cancellable is not %NULL, then the operation can be cancelled 541 * by triggering the cancellable object from another thread. If the 542 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 543 * returned. 544 * 545 * If a file or directory with this name already exists, the 546 * %G_IO_ERROR_EXISTS error will be returned. Some file systems don't 547 * allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME 548 * error, and if the name is too long, %G_IO_ERROR_FILENAME_TOO_LONG 549 * will be returned. Other errors are possible too, and depend on what 550 * kind of filesystem the file is on. 551 * 552 * Note that in many non-local file cases read and write streams are 553 * not supported, so make sure you really need to do read and write 554 * streaming, rather than just opening for reading or writing. 555 * 556 * Params: 557 * flags = a set of #GFileCreateFlags 558 * cancellable = optional #GCancellable object, 559 * %NULL to ignore 560 * 561 * Return: a #GFileIOStream for the newly created 562 * file, or %NULL on error. 563 * Free the returned object with g_object_unref(). 564 * 565 * Since: 2.22 566 * 567 * Throws: GException on failure. 568 */ 569 public FileIOStream createReadwrite(GFileCreateFlags flags, Cancellable cancellable) 570 { 571 GError* err = null; 572 573 auto p = g_file_create_readwrite(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 574 575 if (err !is null) 576 { 577 throw new GException( new ErrorG(err) ); 578 } 579 580 if(p is null) 581 { 582 return null; 583 } 584 585 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 586 } 587 588 /** 589 * Asynchronously creates a new file and returns a stream 590 * for reading and writing to it. The file must not already exist. 591 * 592 * For more details, see g_file_create_readwrite() which is 593 * the synchronous version of this call. 594 * 595 * When the operation is finished, @callback will be called. 596 * You can then call g_file_create_readwrite_finish() to get 597 * the result of the operation. 598 * 599 * Params: 600 * flags = a set of #GFileCreateFlags 601 * ioPriority = the [I/O priority][io-priority] of the request 602 * cancellable = optional #GCancellable object, 603 * %NULL to ignore 604 * callback = a #GAsyncReadyCallback to call 605 * when the request is satisfied 606 * userData = the data to pass to callback function 607 * 608 * Since: 2.22 609 */ 610 public void createReadwriteAsync(GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 611 { 612 g_file_create_readwrite_async(getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 613 } 614 615 /** 616 * Finishes an asynchronous file create operation started with 617 * g_file_create_readwrite_async(). 618 * 619 * Params: 620 * res = a #GAsyncResult 621 * 622 * Return: a #GFileIOStream or %NULL on error. 623 * Free the returned object with g_object_unref(). 624 * 625 * Since: 2.22 626 * 627 * Throws: GException on failure. 628 */ 629 public FileIOStream createReadwriteFinish(AsyncResultIF res) 630 { 631 GError* err = null; 632 633 auto p = g_file_create_readwrite_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 634 635 if (err !is null) 636 { 637 throw new GException( new ErrorG(err) ); 638 } 639 640 if(p is null) 641 { 642 return null; 643 } 644 645 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 646 } 647 648 /** 649 * Deletes a file. If the @file is a directory, it will only be 650 * deleted if it is empty. This has the same semantics as g_unlink(). 651 * 652 * If @cancellable is not %NULL, then the operation can be cancelled by 653 * triggering the cancellable object from another thread. If the operation 654 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 655 * 656 * Params: 657 * cancellable = optional #GCancellable object, 658 * %NULL to ignore 659 * 660 * Return: %TRUE if the file was deleted. %FALSE otherwise. 661 * 662 * Throws: GException on failure. 663 */ 664 public bool delet(Cancellable cancellable) 665 { 666 GError* err = null; 667 668 auto p = g_file_delete(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 669 670 if (err !is null) 671 { 672 throw new GException( new ErrorG(err) ); 673 } 674 675 return p; 676 } 677 678 /** 679 * Asynchronously delete a file. If the @file is a directory, it will 680 * only be deleted if it is empty. This has the same semantics as 681 * g_unlink(). 682 * 683 * Params: 684 * ioPriority = the [I/O priority][io-priority] of the request 685 * cancellable = optional #GCancellable object, 686 * %NULL to ignore 687 * callback = a #GAsyncReadyCallback to call 688 * when the request is satisfied 689 * userData = the data to pass to callback function 690 * 691 * Since: 2.34 692 */ 693 public void deleteAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 694 { 695 g_file_delete_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 696 } 697 698 /** 699 * Finishes deleting a file started with g_file_delete_async(). 700 * 701 * Params: 702 * result = a #GAsyncResult 703 * 704 * Return: %TRUE if the file was deleted. %FALSE otherwise. 705 * 706 * Since: 2.34 707 * 708 * Throws: GException on failure. 709 */ 710 public bool deleteFinish(AsyncResultIF result) 711 { 712 GError* err = null; 713 714 auto p = g_file_delete_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 715 716 if (err !is null) 717 { 718 throw new GException( new ErrorG(err) ); 719 } 720 721 return p; 722 } 723 724 /** 725 * Duplicates a #GFile handle. This operation does not duplicate 726 * the actual file or directory represented by the #GFile; see 727 * g_file_copy() if attempting to copy a file. 728 * 729 * This call does no blocking I/O. 730 * 731 * Return: a new #GFile that is a duplicate 732 * of the given #GFile. 733 */ 734 public FileIF dup() 735 { 736 auto p = g_file_dup(getFileStruct()); 737 738 if(p is null) 739 { 740 return null; 741 } 742 743 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 744 } 745 746 /** 747 * Starts an asynchronous eject on a mountable. 748 * When this operation has completed, @callback will be called with 749 * @user_user data, and the operation can be finalized with 750 * g_file_eject_mountable_finish(). 751 * 752 * If @cancellable is not %NULL, then the operation can be cancelled by 753 * triggering the cancellable object from another thread. If the operation 754 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 755 * 756 * Deprecated: Use g_file_eject_mountable_with_operation() instead. 757 * 758 * Params: 759 * flags = flags affecting the operation 760 * cancellable = optional #GCancellable object, 761 * %NULL to ignore 762 * callback = a #GAsyncReadyCallback to call 763 * when the request is satisfied, or %NULL 764 * userData = the data to pass to callback function 765 */ 766 public void ejectMountable(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 767 { 768 g_file_eject_mountable(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 769 } 770 771 /** 772 * Finishes an asynchronous eject operation started by 773 * g_file_eject_mountable(). 774 * 775 * Deprecated: Use g_file_eject_mountable_with_operation_finish() 776 * instead. 777 * 778 * Params: 779 * result = a #GAsyncResult 780 * 781 * Return: %TRUE if the @file was ejected successfully. 782 * %FALSE otherwise. 783 * 784 * Throws: GException on failure. 785 */ 786 public bool ejectMountableFinish(AsyncResultIF result) 787 { 788 GError* err = null; 789 790 auto p = g_file_eject_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 791 792 if (err !is null) 793 { 794 throw new GException( new ErrorG(err) ); 795 } 796 797 return p; 798 } 799 800 /** 801 * Starts an asynchronous eject on a mountable. 802 * When this operation has completed, @callback will be called with 803 * @user_user data, and the operation can be finalized with 804 * g_file_eject_mountable_with_operation_finish(). 805 * 806 * If @cancellable is not %NULL, then the operation can be cancelled by 807 * triggering the cancellable object from another thread. If the operation 808 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 809 * 810 * Params: 811 * flags = flags affecting the operation 812 * mountOperation = a #GMountOperation, 813 * or %NULL to avoid user interaction 814 * cancellable = optional #GCancellable object, 815 * %NULL to ignore 816 * callback = a #GAsyncReadyCallback to call 817 * when the request is satisfied, or %NULL 818 * userData = the data to pass to callback function 819 * 820 * Since: 2.22 821 */ 822 public void ejectMountableWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 823 { 824 g_file_eject_mountable_with_operation(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 825 } 826 827 /** 828 * Finishes an asynchronous eject operation started by 829 * g_file_eject_mountable_with_operation(). 830 * 831 * Params: 832 * result = a #GAsyncResult 833 * 834 * Return: %TRUE if the @file was ejected successfully. 835 * %FALSE otherwise. 836 * 837 * Since: 2.22 838 * 839 * Throws: GException on failure. 840 */ 841 public bool ejectMountableWithOperationFinish(AsyncResultIF result) 842 { 843 GError* err = null; 844 845 auto p = g_file_eject_mountable_with_operation_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 846 847 if (err !is null) 848 { 849 throw new GException( new ErrorG(err) ); 850 } 851 852 return p; 853 } 854 855 /** 856 * Gets the requested information about the files in a directory. 857 * The result is a #GFileEnumerator object that will give out 858 * #GFileInfo objects for all the files in the directory. 859 * 860 * The @attributes value is a string that specifies the file 861 * attributes that should be gathered. It is not an error if 862 * it's not possible to read a particular requested attribute 863 * from a file - it just won't be set. @attributes should 864 * be a comma-separated list of attributes or attribute wildcards. 865 * The wildcard "*" means all attributes, and a wildcard like 866 * "standard::*" means all attributes in the standard namespace. 867 * An example attribute query be "standard::*,owner::user". 868 * The standard attributes are available as defines, like 869 * #G_FILE_ATTRIBUTE_STANDARD_NAME. 870 * 871 * If @cancellable is not %NULL, then the operation can be cancelled 872 * by triggering the cancellable object from another thread. If the 873 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 874 * returned. 875 * 876 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will 877 * be returned. If the file is not a directory, the %G_IO_ERROR_NOT_DIRECTORY 878 * error will be returned. Other errors are possible too. 879 * 880 * Params: 881 * attributes = an attribute query string 882 * flags = a set of #GFileQueryInfoFlags 883 * cancellable = optional #GCancellable object, 884 * %NULL to ignore 885 * 886 * Return: A #GFileEnumerator if successful, 887 * %NULL on error. Free the returned object with g_object_unref(). 888 * 889 * Throws: GException on failure. 890 */ 891 public FileEnumerator enumerateChildren(string attributes, GFileQueryInfoFlags flags, Cancellable cancellable) 892 { 893 GError* err = null; 894 895 auto p = g_file_enumerate_children(getFileStruct(), Str.toStringz(attributes), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 896 897 if (err !is null) 898 { 899 throw new GException( new ErrorG(err) ); 900 } 901 902 if(p is null) 903 { 904 return null; 905 } 906 907 return ObjectG.getDObject!(FileEnumerator)(cast(GFileEnumerator*) p, true); 908 } 909 910 /** 911 * Asynchronously gets the requested information about the files 912 * in a directory. The result is a #GFileEnumerator object that will 913 * give out #GFileInfo objects for all the files in the directory. 914 * 915 * For more details, see g_file_enumerate_children() which is 916 * the synchronous version of this call. 917 * 918 * When the operation is finished, @callback will be called. You can 919 * then call g_file_enumerate_children_finish() to get the result of 920 * the operation. 921 * 922 * Params: 923 * attributes = an attribute query string 924 * flags = a set of #GFileQueryInfoFlags 925 * ioPriority = the [I/O priority][io-priority] of the request 926 * cancellable = optional #GCancellable object, 927 * %NULL to ignore 928 * callback = a #GAsyncReadyCallback to call when the 929 * request is satisfied 930 * userData = the data to pass to callback function 931 */ 932 public void enumerateChildrenAsync(string attributes, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 933 { 934 g_file_enumerate_children_async(getFileStruct(), Str.toStringz(attributes), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 935 } 936 937 /** 938 * Finishes an async enumerate children operation. 939 * See g_file_enumerate_children_async(). 940 * 941 * Params: 942 * res = a #GAsyncResult 943 * 944 * Return: a #GFileEnumerator or %NULL 945 * if an error occurred. 946 * Free the returned object with g_object_unref(). 947 * 948 * Throws: GException on failure. 949 */ 950 public FileEnumerator enumerateChildrenFinish(AsyncResultIF res) 951 { 952 GError* err = null; 953 954 auto p = g_file_enumerate_children_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 955 956 if (err !is null) 957 { 958 throw new GException( new ErrorG(err) ); 959 } 960 961 if(p is null) 962 { 963 return null; 964 } 965 966 return ObjectG.getDObject!(FileEnumerator)(cast(GFileEnumerator*) p, true); 967 } 968 969 /** 970 * Checks if the two given #GFiles refer to the same file. 971 * 972 * Note that two #GFiles that differ can still refer to the same 973 * file on the filesystem due to various forms of filename 974 * aliasing. 975 * 976 * This call does no blocking I/O. 977 * 978 * Params: 979 * file2 = the second #GFile 980 * 981 * Return: %TRUE if @file1 and @file2 are equal. 982 */ 983 public bool equal(FileIF file2) 984 { 985 return g_file_equal(getFileStruct(), (file2 is null) ? null : file2.getFileStruct()) != 0; 986 } 987 988 /** 989 * Gets a #GMount for the #GFile. 990 * 991 * If the #GFileIface for @file does not have a mount (e.g. 992 * possibly a remote share), @error will be set to %G_IO_ERROR_NOT_FOUND 993 * and %NULL will be returned. 994 * 995 * If @cancellable is not %NULL, then the operation can be cancelled by 996 * triggering the cancellable object from another thread. If the operation 997 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 998 * 999 * Params: 1000 * cancellable = optional #GCancellable object, 1001 * %NULL to ignore 1002 * 1003 * Return: a #GMount where the @file is located 1004 * or %NULL on error. 1005 * Free the returned object with g_object_unref(). 1006 * 1007 * Throws: GException on failure. 1008 */ 1009 public MountIF findEnclosingMount(Cancellable cancellable) 1010 { 1011 GError* err = null; 1012 1013 auto p = g_file_find_enclosing_mount(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1014 1015 if (err !is null) 1016 { 1017 throw new GException( new ErrorG(err) ); 1018 } 1019 1020 if(p is null) 1021 { 1022 return null; 1023 } 1024 1025 return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p); 1026 } 1027 1028 /** 1029 * Asynchronously gets the mount for the file. 1030 * 1031 * For more details, see g_file_find_enclosing_mount() which is 1032 * the synchronous version of this call. 1033 * 1034 * When the operation is finished, @callback will be called. 1035 * You can then call g_file_find_enclosing_mount_finish() to 1036 * get the result of the operation. 1037 * 1038 * Params: 1039 * ioPriority = the [I/O priority][io-priority] of the request 1040 * cancellable = optional #GCancellable object, 1041 * %NULL to ignore 1042 * callback = a #GAsyncReadyCallback to call 1043 * when the request is satisfied 1044 * userData = the data to pass to callback function 1045 */ 1046 public void findEnclosingMountAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1047 { 1048 g_file_find_enclosing_mount_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1049 } 1050 1051 /** 1052 * Finishes an asynchronous find mount request. 1053 * See g_file_find_enclosing_mount_async(). 1054 * 1055 * Params: 1056 * res = a #GAsyncResult 1057 * 1058 * Return: #GMount for given @file or %NULL on error. 1059 * Free the returned object with g_object_unref(). 1060 * 1061 * Throws: GException on failure. 1062 */ 1063 public MountIF findEnclosingMountFinish(AsyncResultIF res) 1064 { 1065 GError* err = null; 1066 1067 auto p = g_file_find_enclosing_mount_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 1068 1069 if (err !is null) 1070 { 1071 throw new GException( new ErrorG(err) ); 1072 } 1073 1074 if(p is null) 1075 { 1076 return null; 1077 } 1078 1079 return ObjectG.getDObject!(Mount, MountIF)(cast(GMount*) p); 1080 } 1081 1082 /** 1083 * Gets the base name (the last component of the path) for a given #GFile. 1084 * 1085 * If called for the top level of a system (such as the filesystem root 1086 * or a uri like sftp://host/) it will return a single directory separator 1087 * (and on Windows, possibly a drive letter). 1088 * 1089 * The base name is a byte string (not UTF-8). It has no defined encoding 1090 * or rules other than it may not contain zero bytes. If you want to use 1091 * filenames in a user interface you should use the display name that you 1092 * can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME 1093 * attribute with g_file_query_info(). 1094 * 1095 * This call does no blocking I/O. 1096 * 1097 * Return: string containing the #GFile's base name, or 1098 * %NULL if given #GFile is invalid. The returned string should be 1099 * freed with g_free() when no longer needed. 1100 */ 1101 public string getBasename() 1102 { 1103 return Str.toString(g_file_get_basename(getFileStruct())); 1104 } 1105 1106 /** 1107 * Gets a child of @file with basename equal to @name. 1108 * 1109 * Note that the file with that specific name might not exist, but 1110 * you can still have a #GFile that points to it. You can use this 1111 * for instance to create that file. 1112 * 1113 * This call does no blocking I/O. 1114 * 1115 * Params: 1116 * name = string containing the child's basename 1117 * 1118 * Return: a #GFile to a child specified by @name. 1119 * Free the returned object with g_object_unref(). 1120 */ 1121 public FileIF getChild(string name) 1122 { 1123 auto p = g_file_get_child(getFileStruct(), Str.toStringz(name)); 1124 1125 if(p is null) 1126 { 1127 return null; 1128 } 1129 1130 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 1131 } 1132 1133 /** 1134 * Gets the child of @file for a given @display_name (i.e. a UTF-8 1135 * version of the name). If this function fails, it returns %NULL 1136 * and @error will be set. This is very useful when constructing a 1137 * #GFile for a new file and the user entered the filename in the 1138 * user interface, for instance when you select a directory and 1139 * type a filename in the file selector. 1140 * 1141 * This call does no blocking I/O. 1142 * 1143 * Params: 1144 * displayName = string to a possible child 1145 * 1146 * Return: a #GFile to the specified child, or 1147 * %NULL if the display name couldn't be converted. 1148 * Free the returned object with g_object_unref(). 1149 * 1150 * Throws: GException on failure. 1151 */ 1152 public FileIF getChildForDisplayName(string displayName) 1153 { 1154 GError* err = null; 1155 1156 auto p = g_file_get_child_for_display_name(getFileStruct(), Str.toStringz(displayName), &err); 1157 1158 if (err !is null) 1159 { 1160 throw new GException( new ErrorG(err) ); 1161 } 1162 1163 if(p is null) 1164 { 1165 return null; 1166 } 1167 1168 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 1169 } 1170 1171 /** 1172 * Gets the parent directory for the @file. 1173 * If the @file represents the root directory of the 1174 * file system, then %NULL will be returned. 1175 * 1176 * This call does no blocking I/O. 1177 * 1178 * Return: a #GFile structure to the 1179 * parent of the given #GFile or %NULL if there is no parent. Free 1180 * the returned object with g_object_unref(). 1181 */ 1182 public FileIF getParent() 1183 { 1184 auto p = g_file_get_parent(getFileStruct()); 1185 1186 if(p is null) 1187 { 1188 return null; 1189 } 1190 1191 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 1192 } 1193 1194 /** 1195 * Gets the parse name of the @file. 1196 * A parse name is a UTF-8 string that describes the 1197 * file such that one can get the #GFile back using 1198 * g_file_parse_name(). 1199 * 1200 * This is generally used to show the #GFile as a nice 1201 * full-pathname kind of string in a user interface, 1202 * like in a location entry. 1203 * 1204 * For local files with names that can safely be converted 1205 * to UTF-8 the pathname is used, otherwise the IRI is used 1206 * (a form of URI that allows UTF-8 characters unescaped). 1207 * 1208 * This call does no blocking I/O. 1209 * 1210 * Return: a string containing the #GFile's parse name. 1211 * The returned string should be freed with g_free() 1212 * when no longer needed. 1213 */ 1214 public string getParseName() 1215 { 1216 return Str.toString(g_file_get_parse_name(getFileStruct())); 1217 } 1218 1219 /** 1220 * Gets the local pathname for #GFile, if one exists. If non-%NULL, this is 1221 * guaranteed to be an absolute, canonical path. It might contain symlinks. 1222 * 1223 * This call does no blocking I/O. 1224 * 1225 * Return: string containing the #GFile's path, or %NULL 1226 * if no such path exists. The returned string should be freed 1227 * with g_free() when no longer needed. 1228 */ 1229 public string getPath() 1230 { 1231 return Str.toString(g_file_get_path(getFileStruct())); 1232 } 1233 1234 /** 1235 * Gets the path for @descendant relative to @parent. 1236 * 1237 * This call does no blocking I/O. 1238 * 1239 * Params: 1240 * descendant = input #GFile 1241 * 1242 * Return: string with the relative path from @descendant 1243 * to @parent, or %NULL if @descendant doesn't have @parent as 1244 * prefix. The returned string should be freed with g_free() when 1245 * no longer needed. 1246 */ 1247 public string getRelativePath(FileIF descendant) 1248 { 1249 return Str.toString(g_file_get_relative_path(getFileStruct(), (descendant is null) ? null : descendant.getFileStruct())); 1250 } 1251 1252 /** 1253 * Gets the URI for the @file. 1254 * 1255 * This call does no blocking I/O. 1256 * 1257 * Return: a string containing the #GFile's URI. 1258 * The returned string should be freed with g_free() 1259 * when no longer needed. 1260 */ 1261 public string getUri() 1262 { 1263 return Str.toString(g_file_get_uri(getFileStruct())); 1264 } 1265 1266 /** 1267 * Gets the URI scheme for a #GFile. 1268 * RFC 3986 decodes the scheme as: 1269 * |[ 1270 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 1271 * ]| 1272 * Common schemes include "file", "http", "ftp", etc. 1273 * 1274 * This call does no blocking I/O. 1275 * 1276 * Return: a string containing the URI scheme for the given 1277 * #GFile. The returned string should be freed with g_free() 1278 * when no longer needed. 1279 */ 1280 public string getUriScheme() 1281 { 1282 return Str.toString(g_file_get_uri_scheme(getFileStruct())); 1283 } 1284 1285 /** 1286 * Checks if @file has a parent, and optionally, if it is @parent. 1287 * 1288 * If @parent is %NULL then this function returns %TRUE if @file has any 1289 * parent at all. If @parent is non-%NULL then %TRUE is only returned 1290 * if @file is an immediate child of @parent. 1291 * 1292 * Params: 1293 * parent = the parent to check for, or %NULL 1294 * 1295 * Return: %TRUE if @file is an immediate child of @parent (or any parent in 1296 * the case that @parent is %NULL). 1297 * 1298 * Since: 2.24 1299 */ 1300 public bool hasParent(FileIF parent) 1301 { 1302 return g_file_has_parent(getFileStruct(), (parent is null) ? null : parent.getFileStruct()) != 0; 1303 } 1304 1305 /** 1306 * Checks whether @file has the prefix specified by @prefix. 1307 * 1308 * In other words, if the names of initial elements of @file's 1309 * pathname match @prefix. Only full pathname elements are matched, 1310 * so a path like /foo is not considered a prefix of /foobar, only 1311 * of /foo/bar. 1312 * 1313 * A #GFile is not a prefix of itself. If you want to check for 1314 * equality, use g_file_equal(). 1315 * 1316 * This call does no I/O, as it works purely on names. As such it can 1317 * sometimes return %FALSE even if @file is inside a @prefix (from a 1318 * filesystem point of view), because the prefix of @file is an alias 1319 * of @prefix. 1320 * 1321 * Params: 1322 * prefix = input #GFile 1323 * 1324 * Return: %TRUE if the @files's parent, grandparent, etc is @prefix, 1325 * %FALSE otherwise. 1326 */ 1327 public bool hasPrefix(FileIF prefix) 1328 { 1329 return g_file_has_prefix(getFileStruct(), (prefix is null) ? null : prefix.getFileStruct()) != 0; 1330 } 1331 1332 /** 1333 * Checks to see if a #GFile has a given URI scheme. 1334 * 1335 * This call does no blocking I/O. 1336 * 1337 * Params: 1338 * uriScheme = a string containing a URI scheme 1339 * 1340 * Return: %TRUE if #GFile's backend supports the 1341 * given URI scheme, %FALSE if URI scheme is %NULL, 1342 * not supported, or #GFile is invalid. 1343 */ 1344 public bool hasUriScheme(string uriScheme) 1345 { 1346 return g_file_has_uri_scheme(getFileStruct(), Str.toStringz(uriScheme)) != 0; 1347 } 1348 1349 /** 1350 * Creates a hash value for a #GFile. 1351 * 1352 * This call does no blocking I/O. 1353 * 1354 * Return: 0 if @file is not a valid #GFile, otherwise an 1355 * integer that can be used as hash value for the #GFile. 1356 * This function is intended for easily hashing a #GFile to 1357 * add to a #GHashTable or similar data structure. 1358 */ 1359 public uint hash() 1360 { 1361 return g_file_hash(getFileStruct()); 1362 } 1363 1364 /** 1365 * Checks to see if a file is native to the platform. 1366 * 1367 * A native file s one expressed in the platform-native filename format, 1368 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local, 1369 * as it might be on a locally mounted remote filesystem. 1370 * 1371 * On some systems non-native files may be available using the native 1372 * filesystem via a userspace filesystem (FUSE), in these cases this call 1373 * will return %FALSE, but g_file_get_path() will still return a native path. 1374 * 1375 * This call does no blocking I/O. 1376 * 1377 * Return: %TRUE if @file is native 1378 */ 1379 public bool isNative() 1380 { 1381 return g_file_is_native(getFileStruct()) != 0; 1382 } 1383 1384 /** 1385 * Loads the content of the file into memory. The data is always 1386 * zero-terminated, but this is not included in the resultant @length. 1387 * The returned @content should be freed with g_free() when no longer 1388 * needed. 1389 * 1390 * If @cancellable is not %NULL, then the operation can be cancelled by 1391 * triggering the cancellable object from another thread. If the operation 1392 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1393 * 1394 * Params: 1395 * cancellable = optional #GCancellable object, %NULL to ignore 1396 * contents = a location to place the contents of the file 1397 * length = a location to place the length of the contents of the file, 1398 * or %NULL if the length is not needed 1399 * etagOut = a location to place the current entity tag for the file, 1400 * or %NULL if the entity tag is not needed 1401 * 1402 * Return: %TRUE if the @file's contents were successfully loaded. 1403 * %FALSE if there were errors. 1404 * 1405 * Throws: GException on failure. 1406 */ 1407 public bool loadContents(Cancellable cancellable, out string contents, out string etagOut) 1408 { 1409 char* outcontents = null; 1410 size_t length; 1411 char* outetagOut = null; 1412 GError* err = null; 1413 1414 auto p = g_file_load_contents(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1415 1416 if (err !is null) 1417 { 1418 throw new GException( new ErrorG(err) ); 1419 } 1420 1421 contents = Str.toString(outcontents, length); 1422 etagOut = Str.toString(outetagOut); 1423 1424 return p; 1425 } 1426 1427 /** 1428 * Starts an asynchronous load of the @file's contents. 1429 * 1430 * For more details, see g_file_load_contents() which is 1431 * the synchronous version of this call. 1432 * 1433 * When the load operation has completed, @callback will be called 1434 * with @user data. To finish the operation, call 1435 * g_file_load_contents_finish() with the #GAsyncResult returned by 1436 * the @callback. 1437 * 1438 * If @cancellable is not %NULL, then the operation can be cancelled by 1439 * triggering the cancellable object from another thread. If the operation 1440 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1441 * 1442 * Params: 1443 * cancellable = optional #GCancellable object, %NULL to ignore 1444 * callback = a #GAsyncReadyCallback to call when the request is satisfied 1445 * userData = the data to pass to callback function 1446 */ 1447 public void loadContentsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1448 { 1449 g_file_load_contents_async(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1450 } 1451 1452 /** 1453 * Finishes an asynchronous load of the @file's contents. 1454 * The contents are placed in @contents, and @length is set to the 1455 * size of the @contents string. The @content should be freed with 1456 * g_free() when no longer needed. If @etag_out is present, it will be 1457 * set to the new entity tag for the @file. 1458 * 1459 * Params: 1460 * res = a #GAsyncResult 1461 * contents = a location to place the contents of the file 1462 * length = a location to place the length of the contents of the file, 1463 * or %NULL if the length is not needed 1464 * etagOut = a location to place the current entity tag for the file, 1465 * or %NULL if the entity tag is not needed 1466 * 1467 * Return: %TRUE if the load was successful. If %FALSE and @error is 1468 * present, it will be set appropriately. 1469 * 1470 * Throws: GException on failure. 1471 */ 1472 public bool loadContentsFinish(AsyncResultIF res, out string contents, out string etagOut) 1473 { 1474 char* outcontents = null; 1475 size_t length; 1476 char* outetagOut = null; 1477 GError* err = null; 1478 1479 auto p = g_file_load_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1480 1481 if (err !is null) 1482 { 1483 throw new GException( new ErrorG(err) ); 1484 } 1485 1486 contents = Str.toString(outcontents, length); 1487 etagOut = Str.toString(outetagOut); 1488 1489 return p; 1490 } 1491 1492 /** 1493 * Reads the partial contents of a file. A #GFileReadMoreCallback should 1494 * be used to stop reading from the file when appropriate, else this 1495 * function will behave exactly as g_file_load_contents_async(). This 1496 * operation can be finished by g_file_load_partial_contents_finish(). 1497 * 1498 * Users of this function should be aware that @user_data is passed to 1499 * both the @read_more_callback and the @callback. 1500 * 1501 * If @cancellable is not %NULL, then the operation can be cancelled by 1502 * triggering the cancellable object from another thread. If the operation 1503 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1504 * 1505 * Params: 1506 * cancellable = optional #GCancellable object, %NULL to ignore 1507 * readMoreCallback = a #GFileReadMoreCallback to receive partial data 1508 * and to specify whether further data should be read 1509 * callback = a #GAsyncReadyCallback to call when the request is satisfied 1510 * userData = the data to pass to the callback functions 1511 */ 1512 public void loadPartialContentsAsync(Cancellable cancellable, GFileReadMoreCallback readMoreCallback, GAsyncReadyCallback callback, void* userData) 1513 { 1514 g_file_load_partial_contents_async(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), readMoreCallback, callback, userData); 1515 } 1516 1517 /** 1518 * Finishes an asynchronous partial load operation that was started 1519 * with g_file_load_partial_contents_async(). The data is always 1520 * zero-terminated, but this is not included in the resultant @length. 1521 * The returned @content should be freed with g_free() when no longer 1522 * needed. 1523 * 1524 * Params: 1525 * res = a #GAsyncResult 1526 * contents = a location to place the contents of the file 1527 * length = a location to place the length of the contents of the file, 1528 * or %NULL if the length is not needed 1529 * etagOut = a location to place the current entity tag for the file, 1530 * or %NULL if the entity tag is not needed 1531 * 1532 * Return: %TRUE if the load was successful. If %FALSE and @error is 1533 * present, it will be set appropriately. 1534 * 1535 * Throws: GException on failure. 1536 */ 1537 public bool loadPartialContentsFinish(AsyncResultIF res, out string contents, out string etagOut) 1538 { 1539 char* outcontents = null; 1540 size_t length; 1541 char* outetagOut = null; 1542 GError* err = null; 1543 1544 auto p = g_file_load_partial_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1545 1546 if (err !is null) 1547 { 1548 throw new GException( new ErrorG(err) ); 1549 } 1550 1551 contents = Str.toString(outcontents, length); 1552 etagOut = Str.toString(outetagOut); 1553 1554 return p; 1555 } 1556 1557 /** 1558 * Creates a directory. Note that this will only create a child directory 1559 * of the immediate parent directory of the path or URI given by the #GFile. 1560 * To recursively create directories, see g_file_make_directory_with_parents(). 1561 * This function will fail if the parent directory does not exist, setting 1562 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support 1563 * creating directories, this function will fail, setting @error to 1564 * %G_IO_ERROR_NOT_SUPPORTED. 1565 * 1566 * For a local #GFile the newly created directory will have the default 1567 * (current) ownership and permissions of the current process. 1568 * 1569 * If @cancellable is not %NULL, then the operation can be cancelled by 1570 * triggering the cancellable object from another thread. If the operation 1571 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1572 * 1573 * Params: 1574 * cancellable = optional #GCancellable object, 1575 * %NULL to ignore 1576 * 1577 * Return: %TRUE on successful creation, %FALSE otherwise. 1578 * 1579 * Throws: GException on failure. 1580 */ 1581 public bool makeDirectory(Cancellable cancellable) 1582 { 1583 GError* err = null; 1584 1585 auto p = g_file_make_directory(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1586 1587 if (err !is null) 1588 { 1589 throw new GException( new ErrorG(err) ); 1590 } 1591 1592 return p; 1593 } 1594 1595 /** 1596 * Asynchronously creates a directory. 1597 * 1598 * Params: 1599 * ioPriority = the [I/O priority][io-priority] of the request 1600 * cancellable = optional #GCancellable object, 1601 * %NULL to ignore 1602 * callback = a #GAsyncReadyCallback to call 1603 * when the request is satisfied 1604 * userData = the data to pass to callback function 1605 * 1606 * Since: 2.38 1607 */ 1608 public void makeDirectoryAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1609 { 1610 g_file_make_directory_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1611 } 1612 1613 /** 1614 * Finishes an asynchronous directory creation, started with 1615 * g_file_make_directory_async(). 1616 * 1617 * Params: 1618 * result = a #GAsyncResult 1619 * 1620 * Return: %TRUE on successful directory creation, %FALSE otherwise. 1621 * 1622 * Since: 2.38 1623 * 1624 * Throws: GException on failure. 1625 */ 1626 public bool makeDirectoryFinish(AsyncResultIF result) 1627 { 1628 GError* err = null; 1629 1630 auto p = g_file_make_directory_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 1631 1632 if (err !is null) 1633 { 1634 throw new GException( new ErrorG(err) ); 1635 } 1636 1637 return p; 1638 } 1639 1640 /** 1641 * Creates a directory and any parent directories that may not 1642 * exist similar to 'mkdir -p'. If the file system does not support 1643 * creating directories, this function will fail, setting @error to 1644 * %G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists, 1645 * this function will fail setting @error to %G_IO_ERROR_EXISTS, unlike 1646 * the similar g_mkdir_with_parents(). 1647 * 1648 * For a local #GFile the newly created directories will have the default 1649 * (current) ownership and permissions of the current process. 1650 * 1651 * If @cancellable is not %NULL, then the operation can be cancelled by 1652 * triggering the cancellable object from another thread. If the operation 1653 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1654 * 1655 * Params: 1656 * cancellable = optional #GCancellable object, 1657 * %NULL to ignore 1658 * 1659 * Return: %TRUE if all directories have been successfully created, %FALSE 1660 * otherwise. 1661 * 1662 * Since: 2.18 1663 * 1664 * Throws: GException on failure. 1665 */ 1666 public bool makeDirectoryWithParents(Cancellable cancellable) 1667 { 1668 GError* err = null; 1669 1670 auto p = g_file_make_directory_with_parents(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1671 1672 if (err !is null) 1673 { 1674 throw new GException( new ErrorG(err) ); 1675 } 1676 1677 return p; 1678 } 1679 1680 /** 1681 * Creates a symbolic link named @file which contains the string 1682 * @symlink_value. 1683 * 1684 * If @cancellable is not %NULL, then the operation can be cancelled by 1685 * triggering the cancellable object from another thread. If the operation 1686 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1687 * 1688 * Params: 1689 * symlinkValue = a string with the path for the target of the new symlink 1690 * cancellable = optional #GCancellable object, 1691 * %NULL to ignore 1692 * 1693 * Return: %TRUE on the creation of a new symlink, %FALSE otherwise. 1694 * 1695 * Throws: GException on failure. 1696 */ 1697 public bool makeSymbolicLink(string symlinkValue, Cancellable cancellable) 1698 { 1699 GError* err = null; 1700 1701 auto p = g_file_make_symbolic_link(getFileStruct(), Str.toStringz(symlinkValue), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1702 1703 if (err !is null) 1704 { 1705 throw new GException( new ErrorG(err) ); 1706 } 1707 1708 return p; 1709 } 1710 1711 /** 1712 * Recursively measures the disk usage of @file. 1713 * 1714 * This is essentially an analog of the 'du' command, but it also 1715 * reports the number of directories and non-directory files encountered 1716 * (including things like symbolic links). 1717 * 1718 * By default, errors are only reported against the toplevel file 1719 * itself. Errors found while recursing are silently ignored, unless 1720 * %G_FILE_DISK_USAGE_REPORT_ALL_ERRORS is given in @flags. 1721 * 1722 * The returned size, @disk_usage, is in bytes and should be formatted 1723 * with g_format_size() in order to get something reasonable for showing 1724 * in a user interface. 1725 * 1726 * @progress_callback and @progress_data can be given to request 1727 * periodic progress updates while scanning. See the documentation for 1728 * #GFileMeasureProgressCallback for information about when and how the 1729 * callback will be invoked. 1730 * 1731 * Params: 1732 * flags = #GFileMeasureFlags 1733 * cancellable = optional #GCancellable 1734 * progressCallback = a #GFileMeasureProgressCallback 1735 * progressData = user_data for @progress_callback 1736 * diskUsage = the number of bytes of disk space used 1737 * numDirs = the number of directories encountered 1738 * numFiles = the number of non-directories encountered 1739 * 1740 * Return: %TRUE if successful, with the out parameters set. 1741 * %FALSE otherwise, with @error set. 1742 * 1743 * Since: 2.38 1744 * 1745 * Throws: GException on failure. 1746 */ 1747 public bool measureDiskUsage(GFileMeasureFlags flags, Cancellable cancellable, GFileMeasureProgressCallback progressCallback, void* progressData, out ulong diskUsage, out ulong numDirs, out ulong numFiles) 1748 { 1749 GError* err = null; 1750 1751 auto p = g_file_measure_disk_usage(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressData, &diskUsage, &numDirs, &numFiles, &err) != 0; 1752 1753 if (err !is null) 1754 { 1755 throw new GException( new ErrorG(err) ); 1756 } 1757 1758 return p; 1759 } 1760 1761 /** 1762 * Recursively measures the disk usage of @file. 1763 * 1764 * This is the asynchronous version of g_file_measure_disk_usage(). See 1765 * there for more information. 1766 * 1767 * Params: 1768 * flags = #GFileMeasureFlags 1769 * ioPriority = the [I/O priority][io-priority] of the request 1770 * cancellable = optional #GCancellable 1771 * progressCallback = a #GFileMeasureProgressCallback 1772 * progressData = user_data for @progress_callback 1773 * callback = a #GAsyncReadyCallback to call when complete 1774 * userData = the data to pass to callback function 1775 * 1776 * Since: 2.38 1777 */ 1778 public void measureDiskUsageAsync(GFileMeasureFlags flags, int ioPriority, Cancellable cancellable, GFileMeasureProgressCallback progressCallback, void* progressData, GAsyncReadyCallback callback, void* userData) 1779 { 1780 g_file_measure_disk_usage_async(getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressData, callback, userData); 1781 } 1782 1783 /** 1784 * Collects the results from an earlier call to 1785 * g_file_measure_disk_usage_async(). See g_file_measure_disk_usage() for 1786 * more information. 1787 * 1788 * Params: 1789 * result = the #GAsyncResult passed to your #GAsyncReadyCallback 1790 * diskUsage = the number of bytes of disk space used 1791 * numDirs = the number of directories encountered 1792 * numFiles = the number of non-directories encountered 1793 * 1794 * Return: %TRUE if successful, with the out parameters set. 1795 * %FALSE otherwise, with @error set. 1796 * 1797 * Since: 2.38 1798 * 1799 * Throws: GException on failure. 1800 */ 1801 public bool measureDiskUsageFinish(AsyncResultIF result, out ulong diskUsage, out ulong numDirs, out ulong numFiles) 1802 { 1803 GError* err = null; 1804 1805 auto p = g_file_measure_disk_usage_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &diskUsage, &numDirs, &numFiles, &err) != 0; 1806 1807 if (err !is null) 1808 { 1809 throw new GException( new ErrorG(err) ); 1810 } 1811 1812 return p; 1813 } 1814 1815 /** 1816 * Obtains a file or directory monitor for the given file, 1817 * depending on the type of the file. 1818 * 1819 * If @cancellable is not %NULL, then the operation can be cancelled by 1820 * triggering the cancellable object from another thread. If the operation 1821 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1822 * 1823 * Params: 1824 * flags = a set of #GFileMonitorFlags 1825 * cancellable = optional #GCancellable object, 1826 * %NULL to ignore 1827 * 1828 * Return: a #GFileMonitor for the given @file, 1829 * or %NULL on error. 1830 * Free the returned object with g_object_unref(). 1831 * 1832 * Since: 2.18 1833 * 1834 * Throws: GException on failure. 1835 */ 1836 public FileMonitor monitor(GFileMonitorFlags flags, Cancellable cancellable) 1837 { 1838 GError* err = null; 1839 1840 auto p = g_file_monitor(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1841 1842 if (err !is null) 1843 { 1844 throw new GException( new ErrorG(err) ); 1845 } 1846 1847 if(p is null) 1848 { 1849 return null; 1850 } 1851 1852 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1853 } 1854 1855 /** 1856 * Obtains a directory monitor for the given file. 1857 * This may fail if directory monitoring is not supported. 1858 * 1859 * If @cancellable is not %NULL, then the operation can be cancelled by 1860 * triggering the cancellable object from another thread. If the operation 1861 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1862 * 1863 * It does not make sense for @flags to contain 1864 * %G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to 1865 * directories. It is not possible to monitor all the files in a 1866 * directory for changes made via hard links; if you want to do this then 1867 * you must register individual watches with g_file_monitor(). 1868 * 1869 * Params: 1870 * flags = a set of #GFileMonitorFlags 1871 * cancellable = optional #GCancellable object, 1872 * %NULL to ignore 1873 * 1874 * Return: a #GFileMonitor for the given @file, 1875 * or %NULL on error. 1876 * Free the returned object with g_object_unref(). 1877 * 1878 * Throws: GException on failure. 1879 */ 1880 public FileMonitor monitorDirectory(GFileMonitorFlags flags, Cancellable cancellable) 1881 { 1882 GError* err = null; 1883 1884 auto p = g_file_monitor_directory(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1885 1886 if (err !is null) 1887 { 1888 throw new GException( new ErrorG(err) ); 1889 } 1890 1891 if(p is null) 1892 { 1893 return null; 1894 } 1895 1896 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1897 } 1898 1899 /** 1900 * Obtains a file monitor for the given file. If no file notification 1901 * mechanism exists, then regular polling of the file is used. 1902 * 1903 * If @cancellable is not %NULL, then the operation can be cancelled by 1904 * triggering the cancellable object from another thread. If the operation 1905 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1906 * 1907 * If @flags contains %G_FILE_MONITOR_WATCH_HARD_LINKS then the monitor 1908 * will also attempt to report changes made to the file via another 1909 * filename (ie, a hard link). Without this flag, you can only rely on 1910 * changes made through the filename contained in @file to be 1911 * reported. Using this flag may result in an increase in resource 1912 * usage, and may not have any effect depending on the #GFileMonitor 1913 * backend and/or filesystem type. 1914 * 1915 * Params: 1916 * flags = a set of #GFileMonitorFlags 1917 * cancellable = optional #GCancellable object, 1918 * %NULL to ignore 1919 * 1920 * Return: a #GFileMonitor for the given @file, 1921 * or %NULL on error. 1922 * Free the returned object with g_object_unref(). 1923 * 1924 * Throws: GException on failure. 1925 */ 1926 public FileMonitor monitorFile(GFileMonitorFlags flags, Cancellable cancellable) 1927 { 1928 GError* err = null; 1929 1930 auto p = g_file_monitor_file(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1931 1932 if (err !is null) 1933 { 1934 throw new GException( new ErrorG(err) ); 1935 } 1936 1937 if(p is null) 1938 { 1939 return null; 1940 } 1941 1942 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1943 } 1944 1945 /** 1946 * Starts a @mount_operation, mounting the volume that contains 1947 * the file @location. 1948 * 1949 * When this operation has completed, @callback will be called with 1950 * @user_user data, and the operation can be finalized with 1951 * g_file_mount_enclosing_volume_finish(). 1952 * 1953 * If @cancellable is not %NULL, then the operation can be cancelled by 1954 * triggering the cancellable object from another thread. If the operation 1955 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1956 * 1957 * Params: 1958 * flags = flags affecting the operation 1959 * mountOperation = a #GMountOperation 1960 * or %NULL to avoid user interaction 1961 * cancellable = optional #GCancellable object, 1962 * %NULL to ignore 1963 * callback = a #GAsyncReadyCallback to call 1964 * when the request is satisfied, or %NULL 1965 * userData = the data to pass to callback function 1966 */ 1967 public void mountEnclosingVolume(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1968 { 1969 g_file_mount_enclosing_volume(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1970 } 1971 1972 /** 1973 * Finishes a mount operation started by g_file_mount_enclosing_volume(). 1974 * 1975 * Params: 1976 * result = a #GAsyncResult 1977 * 1978 * Return: %TRUE if successful. If an error has occurred, 1979 * this function will return %FALSE and set @error 1980 * appropriately if present. 1981 * 1982 * Throws: GException on failure. 1983 */ 1984 public bool mountEnclosingVolumeFinish(AsyncResultIF result) 1985 { 1986 GError* err = null; 1987 1988 auto p = g_file_mount_enclosing_volume_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 1989 1990 if (err !is null) 1991 { 1992 throw new GException( new ErrorG(err) ); 1993 } 1994 1995 return p; 1996 } 1997 1998 /** 1999 * Mounts a file of type G_FILE_TYPE_MOUNTABLE. 2000 * Using @mount_operation, you can request callbacks when, for instance, 2001 * passwords are needed during authentication. 2002 * 2003 * If @cancellable is not %NULL, then the operation can be cancelled by 2004 * triggering the cancellable object from another thread. If the operation 2005 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2006 * 2007 * When the operation is finished, @callback will be called. 2008 * You can then call g_file_mount_mountable_finish() to get 2009 * the result of the operation. 2010 * 2011 * Params: 2012 * flags = flags affecting the operation 2013 * mountOperation = a #GMountOperation, 2014 * or %NULL to avoid user interaction 2015 * cancellable = optional #GCancellable object, 2016 * %NULL to ignore 2017 * callback = a #GAsyncReadyCallback to call 2018 * when the request is satisfied, or %NULL 2019 * userData = the data to pass to callback function 2020 */ 2021 public void mountMountable(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2022 { 2023 g_file_mount_mountable(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2024 } 2025 2026 /** 2027 * Finishes a mount operation. See g_file_mount_mountable() for details. 2028 * 2029 * Finish an asynchronous mount operation that was started 2030 * with g_file_mount_mountable(). 2031 * 2032 * Params: 2033 * result = a #GAsyncResult 2034 * 2035 * Return: a #GFile or %NULL on error. 2036 * Free the returned object with g_object_unref(). 2037 * 2038 * Throws: GException on failure. 2039 */ 2040 public FileIF mountMountableFinish(AsyncResultIF result) 2041 { 2042 GError* err = null; 2043 2044 auto p = g_file_mount_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err); 2045 2046 if (err !is null) 2047 { 2048 throw new GException( new ErrorG(err) ); 2049 } 2050 2051 if(p is null) 2052 { 2053 return null; 2054 } 2055 2056 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 2057 } 2058 2059 /** 2060 * Tries to move the file or directory @source to the location specified 2061 * by @destination. If native move operations are supported then this is 2062 * used, otherwise a copy + delete fallback is used. The native 2063 * implementation may support moving directories (for instance on moves 2064 * inside the same filesystem), but the fallback code does not. 2065 * 2066 * If the flag #G_FILE_COPY_OVERWRITE is specified an already 2067 * existing @destination file is overwritten. 2068 * 2069 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks 2070 * will be copied as symlinks, otherwise the target of the 2071 * @source symlink will be copied. 2072 * 2073 * If @cancellable is not %NULL, then the operation can be cancelled by 2074 * triggering the cancellable object from another thread. If the operation 2075 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2076 * 2077 * If @progress_callback is not %NULL, then the operation can be monitored 2078 * by setting this to a #GFileProgressCallback function. 2079 * @progress_callback_data will be passed to this function. It is 2080 * guaranteed that this callback will be called after all data has been 2081 * transferred with the total number of bytes copied during the operation. 2082 * 2083 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND 2084 * error is returned, independent on the status of the @destination. 2085 * 2086 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, 2087 * then the error %G_IO_ERROR_EXISTS is returned. 2088 * 2089 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY 2090 * error is returned. If trying to overwrite a directory with a directory the 2091 * %G_IO_ERROR_WOULD_MERGE error is returned. 2092 * 2093 * If the source is a directory and the target does not exist, or 2094 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then 2095 * the %G_IO_ERROR_WOULD_RECURSE error may be returned (if the native 2096 * move operation isn't available). 2097 * 2098 * Params: 2099 * destination = #GFile pointing to the destination location 2100 * flags = set of #GFileCopyFlags 2101 * cancellable = optional #GCancellable object, 2102 * %NULL to ignore 2103 * progressCallback = #GFileProgressCallback 2104 * function for updates 2105 * progressCallbackData = gpointer to user data for 2106 * the callback function 2107 * 2108 * Return: %TRUE on successful move, %FALSE otherwise. 2109 * 2110 * Throws: GException on failure. 2111 */ 2112 public bool move(FileIF destination, GFileCopyFlags flags, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData) 2113 { 2114 GError* err = null; 2115 2116 auto p = g_file_move(getFileStruct(), (destination is null) ? null : destination.getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, &err) != 0; 2117 2118 if (err !is null) 2119 { 2120 throw new GException( new ErrorG(err) ); 2121 } 2122 2123 return p; 2124 } 2125 2126 /** 2127 * Opens an existing file for reading and writing. The result is 2128 * a #GFileIOStream that can be used to read and write the contents 2129 * of the file. 2130 * 2131 * If @cancellable is not %NULL, then the operation can be cancelled 2132 * by triggering the cancellable object from another thread. If the 2133 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2134 * returned. 2135 * 2136 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will 2137 * be returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY 2138 * error will be returned. Other errors are possible too, and depend on 2139 * what kind of filesystem the file is on. Note that in many non-local 2140 * file cases read and write streams are not supported, so make sure you 2141 * really need to do read and write streaming, rather than just opening 2142 * for reading or writing. 2143 * 2144 * Params: 2145 * cancellable = a #GCancellable 2146 * 2147 * Return: #GFileIOStream or %NULL on error. 2148 * Free the returned object with g_object_unref(). 2149 * 2150 * Since: 2.22 2151 * 2152 * Throws: GException on failure. 2153 */ 2154 public FileIOStream openReadwrite(Cancellable cancellable) 2155 { 2156 GError* err = null; 2157 2158 auto p = g_file_open_readwrite(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2159 2160 if (err !is null) 2161 { 2162 throw new GException( new ErrorG(err) ); 2163 } 2164 2165 if(p is null) 2166 { 2167 return null; 2168 } 2169 2170 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 2171 } 2172 2173 /** 2174 * Asynchronously opens @file for reading and writing. 2175 * 2176 * For more details, see g_file_open_readwrite() which is 2177 * the synchronous version of this call. 2178 * 2179 * When the operation is finished, @callback will be called. 2180 * You can then call g_file_open_readwrite_finish() to get 2181 * the result of the operation. 2182 * 2183 * Params: 2184 * ioPriority = the [I/O priority][io-priority] of the request 2185 * cancellable = optional #GCancellable object, 2186 * %NULL to ignore 2187 * callback = a #GAsyncReadyCallback to call 2188 * when the request is satisfied 2189 * userData = the data to pass to callback function 2190 * 2191 * Since: 2.22 2192 */ 2193 public void openReadwriteAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2194 { 2195 g_file_open_readwrite_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2196 } 2197 2198 /** 2199 * Finishes an asynchronous file read operation started with 2200 * g_file_open_readwrite_async(). 2201 * 2202 * Params: 2203 * res = a #GAsyncResult 2204 * 2205 * Return: a #GFileIOStream or %NULL on error. 2206 * Free the returned object with g_object_unref(). 2207 * 2208 * Since: 2.22 2209 * 2210 * Throws: GException on failure. 2211 */ 2212 public FileIOStream openReadwriteFinish(AsyncResultIF res) 2213 { 2214 GError* err = null; 2215 2216 auto p = g_file_open_readwrite_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2217 2218 if (err !is null) 2219 { 2220 throw new GException( new ErrorG(err) ); 2221 } 2222 2223 if(p is null) 2224 { 2225 return null; 2226 } 2227 2228 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 2229 } 2230 2231 /** 2232 * Polls a file of type #G_FILE_TYPE_MOUNTABLE. 2233 * 2234 * If @cancellable is not %NULL, then the operation can be cancelled by 2235 * triggering the cancellable object from another thread. If the operation 2236 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2237 * 2238 * When the operation is finished, @callback will be called. 2239 * You can then call g_file_mount_mountable_finish() to get 2240 * the result of the operation. 2241 * 2242 * Params: 2243 * cancellable = optional #GCancellable object, %NULL to ignore 2244 * callback = a #GAsyncReadyCallback to call 2245 * when the request is satisfied, or %NULL 2246 * userData = the data to pass to callback function 2247 * 2248 * Since: 2.22 2249 */ 2250 public void pollMountable(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2251 { 2252 g_file_poll_mountable(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2253 } 2254 2255 /** 2256 * Finishes a poll operation. See g_file_poll_mountable() for details. 2257 * 2258 * Finish an asynchronous poll operation that was polled 2259 * with g_file_poll_mountable(). 2260 * 2261 * Params: 2262 * result = a #GAsyncResult 2263 * 2264 * Return: %TRUE if the operation finished successfully. %FALSE 2265 * otherwise. 2266 * 2267 * Since: 2.22 2268 * 2269 * Throws: GException on failure. 2270 */ 2271 public bool pollMountableFinish(AsyncResultIF result) 2272 { 2273 GError* err = null; 2274 2275 auto p = g_file_poll_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 2276 2277 if (err !is null) 2278 { 2279 throw new GException( new ErrorG(err) ); 2280 } 2281 2282 return p; 2283 } 2284 2285 /** 2286 * Returns the #GAppInfo that is registered as the default 2287 * application to handle the file specified by @file. 2288 * 2289 * If @cancellable is not %NULL, then the operation can be cancelled by 2290 * triggering the cancellable object from another thread. If the operation 2291 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2292 * 2293 * Params: 2294 * cancellable = optional #GCancellable object, %NULL to ignore 2295 * 2296 * Return: a #GAppInfo if the handle was found, 2297 * %NULL if there were errors. 2298 * When you are done with it, release it with g_object_unref() 2299 * 2300 * Throws: GException on failure. 2301 */ 2302 public AppInfoIF queryDefaultHandler(Cancellable cancellable) 2303 { 2304 GError* err = null; 2305 2306 auto p = g_file_query_default_handler(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2307 2308 if (err !is null) 2309 { 2310 throw new GException( new ErrorG(err) ); 2311 } 2312 2313 if(p is null) 2314 { 2315 return null; 2316 } 2317 2318 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 2319 } 2320 2321 /** 2322 * Utility function to check if a particular file exists. This is 2323 * implemented using g_file_query_info() and as such does blocking I/O. 2324 * 2325 * Note that in many cases it is racy to first check for file existence 2326 * and then execute something based on the outcome of that, because the 2327 * file might have been created or removed in between the operations. The 2328 * general approach to handling that is to not check, but just do the 2329 * operation and handle the errors as they come. 2330 * 2331 * As an example of race-free checking, take the case of reading a file, 2332 * and if it doesn't exist, creating it. There are two racy versions: read 2333 * it, and on error create it; and: check if it exists, if not create it. 2334 * These can both result in two processes creating the file (with perhaps 2335 * a partially written file as the result). The correct approach is to 2336 * always try to create the file with g_file_create() which will either 2337 * atomically create the file or fail with a %G_IO_ERROR_EXISTS error. 2338 * 2339 * However, in many cases an existence check is useful in a user interface, 2340 * for instance to make a menu item sensitive/insensitive, so that you don't 2341 * have to fool users that something is possible and then just show an error 2342 * dialog. If you do this, you should make sure to also handle the errors 2343 * that can happen due to races when you execute the operation. 2344 * 2345 * Params: 2346 * cancellable = optional #GCancellable object, 2347 * %NULL to ignore 2348 * 2349 * Return: %TRUE if the file exists (and can be detected without error), 2350 * %FALSE otherwise (or if cancelled). 2351 */ 2352 public bool queryExists(Cancellable cancellable) 2353 { 2354 return g_file_query_exists(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()) != 0; 2355 } 2356 2357 /** 2358 * Utility function to inspect the #GFileType of a file. This is 2359 * implemented using g_file_query_info() and as such does blocking I/O. 2360 * 2361 * The primary use case of this method is to check if a file is 2362 * a regular file, directory, or symlink. 2363 * 2364 * Params: 2365 * flags = a set of #GFileQueryInfoFlags passed to g_file_query_info() 2366 * cancellable = optional #GCancellable object, 2367 * %NULL to ignore 2368 * 2369 * Return: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN 2370 * if the file does not exist 2371 * 2372 * Since: 2.18 2373 */ 2374 public GFileType queryFileType(GFileQueryInfoFlags flags, Cancellable cancellable) 2375 { 2376 return g_file_query_file_type(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct()); 2377 } 2378 2379 /** 2380 * Similar to g_file_query_info(), but obtains information 2381 * about the filesystem the @file is on, rather than the file itself. 2382 * For instance the amount of space available and the type of 2383 * the filesystem. 2384 * 2385 * The @attributes value is a string that specifies the attributes 2386 * that should be gathered. It is not an error if it's not possible 2387 * to read a particular requested attribute from a file - it just 2388 * won't be set. @attributes should be a comma-separated list of 2389 * attributes or attribute wildcards. The wildcard "*" means all 2390 * attributes, and a wildcard like "filesystem::*" means all attributes 2391 * in the filesystem namespace. The standard namespace for filesystem 2392 * attributes is "filesystem". Common attributes of interest are 2393 * #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem 2394 * in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available), 2395 * and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem). 2396 * 2397 * If @cancellable is not %NULL, then the operation can be cancelled 2398 * by triggering the cancellable object from another thread. If the 2399 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2400 * returned. 2401 * 2402 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will 2403 * be returned. Other errors are possible too, and depend on what 2404 * kind of filesystem the file is on. 2405 * 2406 * Params: 2407 * attributes = an attribute query string 2408 * cancellable = optional #GCancellable object, 2409 * %NULL to ignore 2410 * 2411 * Return: a #GFileInfo or %NULL if there was an error. 2412 * Free the returned object with g_object_unref(). 2413 * 2414 * Throws: GException on failure. 2415 */ 2416 public FileInfo queryFilesystemInfo(string attributes, Cancellable cancellable) 2417 { 2418 GError* err = null; 2419 2420 auto p = g_file_query_filesystem_info(getFileStruct(), Str.toStringz(attributes), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2421 2422 if (err !is null) 2423 { 2424 throw new GException( new ErrorG(err) ); 2425 } 2426 2427 if(p is null) 2428 { 2429 return null; 2430 } 2431 2432 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2433 } 2434 2435 /** 2436 * Asynchronously gets the requested information about the filesystem 2437 * that the specified @file is on. The result is a #GFileInfo object 2438 * that contains key-value attributes (such as type or size for the 2439 * file). 2440 * 2441 * For more details, see g_file_query_filesystem_info() which is the 2442 * synchronous version of this call. 2443 * 2444 * When the operation is finished, @callback will be called. You can 2445 * then call g_file_query_info_finish() to get the result of the 2446 * operation. 2447 * 2448 * Params: 2449 * attributes = an attribute query string 2450 * ioPriority = the [I/O priority][io-priority] of the request 2451 * cancellable = optional #GCancellable object, 2452 * %NULL to ignore 2453 * callback = a #GAsyncReadyCallback to call 2454 * when the request is satisfied 2455 * userData = the data to pass to callback function 2456 */ 2457 public void queryFilesystemInfoAsync(string attributes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2458 { 2459 g_file_query_filesystem_info_async(getFileStruct(), Str.toStringz(attributes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2460 } 2461 2462 /** 2463 * Finishes an asynchronous filesystem info query. 2464 * See g_file_query_filesystem_info_async(). 2465 * 2466 * Params: 2467 * res = a #GAsyncResult 2468 * 2469 * Return: #GFileInfo for given @file 2470 * or %NULL on error. 2471 * Free the returned object with g_object_unref(). 2472 * 2473 * Throws: GException on failure. 2474 */ 2475 public FileInfo queryFilesystemInfoFinish(AsyncResultIF res) 2476 { 2477 GError* err = null; 2478 2479 auto p = g_file_query_filesystem_info_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2480 2481 if (err !is null) 2482 { 2483 throw new GException( new ErrorG(err) ); 2484 } 2485 2486 if(p is null) 2487 { 2488 return null; 2489 } 2490 2491 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2492 } 2493 2494 /** 2495 * Gets the requested information about specified @file. 2496 * The result is a #GFileInfo object that contains key-value 2497 * attributes (such as the type or size of the file). 2498 * 2499 * The @attributes value is a string that specifies the file 2500 * attributes that should be gathered. It is not an error if 2501 * it's not possible to read a particular requested attribute 2502 * from a file - it just won't be set. @attributes should be a 2503 * comma-separated list of attributes or attribute wildcards. 2504 * The wildcard "*" means all attributes, and a wildcard like 2505 * "standard::*" means all attributes in the standard namespace. 2506 * An example attribute query be "standard::*,owner::user". 2507 * The standard attributes are available as defines, like 2508 * #G_FILE_ATTRIBUTE_STANDARD_NAME. 2509 * 2510 * If @cancellable is not %NULL, then the operation can be cancelled 2511 * by triggering the cancellable object from another thread. If the 2512 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2513 * returned. 2514 * 2515 * For symlinks, normally the information about the target of the 2516 * symlink is returned, rather than information about the symlink 2517 * itself. However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS 2518 * in @flags the information about the symlink itself will be returned. 2519 * Also, for symlinks that point to non-existing files the information 2520 * about the symlink itself will be returned. 2521 * 2522 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be 2523 * returned. Other errors are possible too, and depend on what kind of 2524 * filesystem the file is on. 2525 * 2526 * Params: 2527 * attributes = an attribute query string 2528 * flags = a set of #GFileQueryInfoFlags 2529 * cancellable = optional #GCancellable object, 2530 * %NULL to ignore 2531 * 2532 * Return: a #GFileInfo for the given @file, or %NULL 2533 * on error. Free the returned object with g_object_unref(). 2534 * 2535 * Throws: GException on failure. 2536 */ 2537 public FileInfo queryInfo(string attributes, GFileQueryInfoFlags flags, Cancellable cancellable) 2538 { 2539 GError* err = null; 2540 2541 auto p = g_file_query_info(getFileStruct(), Str.toStringz(attributes), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2542 2543 if (err !is null) 2544 { 2545 throw new GException( new ErrorG(err) ); 2546 } 2547 2548 if(p is null) 2549 { 2550 return null; 2551 } 2552 2553 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2554 } 2555 2556 /** 2557 * Asynchronously gets the requested information about specified @file. 2558 * The result is a #GFileInfo object that contains key-value attributes 2559 * (such as type or size for the file). 2560 * 2561 * For more details, see g_file_query_info() which is the synchronous 2562 * version of this call. 2563 * 2564 * When the operation is finished, @callback will be called. You can 2565 * then call g_file_query_info_finish() to get the result of the operation. 2566 * 2567 * Params: 2568 * attributes = an attribute query string 2569 * flags = a set of #GFileQueryInfoFlags 2570 * ioPriority = the [I/O priority][io-priority] of the request 2571 * cancellable = optional #GCancellable object, 2572 * %NULL to ignore 2573 * callback = a #GAsyncReadyCallback to call when the 2574 * request is satisfied 2575 * userData = the data to pass to callback function 2576 */ 2577 public void queryInfoAsync(string attributes, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2578 { 2579 g_file_query_info_async(getFileStruct(), Str.toStringz(attributes), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2580 } 2581 2582 /** 2583 * Finishes an asynchronous file info query. 2584 * See g_file_query_info_async(). 2585 * 2586 * Params: 2587 * res = a #GAsyncResult 2588 * 2589 * Return: #GFileInfo for given @file 2590 * or %NULL on error. Free the returned object with 2591 * g_object_unref(). 2592 * 2593 * Throws: GException on failure. 2594 */ 2595 public FileInfo queryInfoFinish(AsyncResultIF res) 2596 { 2597 GError* err = null; 2598 2599 auto p = g_file_query_info_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2600 2601 if (err !is null) 2602 { 2603 throw new GException( new ErrorG(err) ); 2604 } 2605 2606 if(p is null) 2607 { 2608 return null; 2609 } 2610 2611 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2612 } 2613 2614 /** 2615 * Obtain the list of settable attributes for the file. 2616 * 2617 * Returns the type and full attribute name of all the attributes 2618 * that can be set on this file. This doesn't mean setting it will 2619 * always succeed though, you might get an access failure, or some 2620 * specific file may not support a specific attribute. 2621 * 2622 * If @cancellable is not %NULL, then the operation can be cancelled by 2623 * triggering the cancellable object from another thread. If the operation 2624 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2625 * 2626 * Params: 2627 * cancellable = optional #GCancellable object, 2628 * %NULL to ignore 2629 * 2630 * Return: a #GFileAttributeInfoList describing the settable attributes. 2631 * When you are done with it, release it with 2632 * g_file_attribute_info_list_unref() 2633 * 2634 * Throws: GException on failure. 2635 */ 2636 public FileAttributeInfoList querySettableAttributes(Cancellable cancellable) 2637 { 2638 GError* err = null; 2639 2640 auto p = g_file_query_settable_attributes(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2641 2642 if (err !is null) 2643 { 2644 throw new GException( new ErrorG(err) ); 2645 } 2646 2647 if(p is null) 2648 { 2649 return null; 2650 } 2651 2652 return ObjectG.getDObject!(FileAttributeInfoList)(cast(GFileAttributeInfoList*) p); 2653 } 2654 2655 /** 2656 * Obtain the list of attribute namespaces where new attributes 2657 * can be created by a user. An example of this is extended 2658 * attributes (in the "xattr" namespace). 2659 * 2660 * If @cancellable is not %NULL, then the operation can be cancelled by 2661 * triggering the cancellable object from another thread. If the operation 2662 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2663 * 2664 * Params: 2665 * cancellable = optional #GCancellable object, 2666 * %NULL to ignore 2667 * 2668 * Return: a #GFileAttributeInfoList describing the writable namespaces. 2669 * When you are done with it, release it with 2670 * g_file_attribute_info_list_unref() 2671 * 2672 * Throws: GException on failure. 2673 */ 2674 public FileAttributeInfoList queryWritableNamespaces(Cancellable cancellable) 2675 { 2676 GError* err = null; 2677 2678 auto p = g_file_query_writable_namespaces(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2679 2680 if (err !is null) 2681 { 2682 throw new GException( new ErrorG(err) ); 2683 } 2684 2685 if(p is null) 2686 { 2687 return null; 2688 } 2689 2690 return ObjectG.getDObject!(FileAttributeInfoList)(cast(GFileAttributeInfoList*) p); 2691 } 2692 2693 /** 2694 * Opens a file for reading. The result is a #GFileInputStream that 2695 * can be used to read the contents of the file. 2696 * 2697 * If @cancellable is not %NULL, then the operation can be cancelled by 2698 * triggering the cancellable object from another thread. If the operation 2699 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2700 * 2701 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be 2702 * returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY 2703 * error will be returned. Other errors are possible too, and depend 2704 * on what kind of filesystem the file is on. 2705 * 2706 * Params: 2707 * cancellable = a #GCancellable 2708 * 2709 * Return: #GFileInputStream or %NULL on error. 2710 * Free the returned object with g_object_unref(). 2711 * 2712 * Throws: GException on failure. 2713 */ 2714 public FileInputStream read(Cancellable cancellable) 2715 { 2716 GError* err = null; 2717 2718 auto p = g_file_read(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2719 2720 if (err !is null) 2721 { 2722 throw new GException( new ErrorG(err) ); 2723 } 2724 2725 if(p is null) 2726 { 2727 return null; 2728 } 2729 2730 return ObjectG.getDObject!(FileInputStream)(cast(GFileInputStream*) p, true); 2731 } 2732 2733 /** 2734 * Asynchronously opens @file for reading. 2735 * 2736 * For more details, see g_file_read() which is 2737 * the synchronous version of this call. 2738 * 2739 * When the operation is finished, @callback will be called. 2740 * You can then call g_file_read_finish() to get the result 2741 * of the operation. 2742 * 2743 * Params: 2744 * ioPriority = the [I/O priority][io-priority] of the request 2745 * cancellable = optional #GCancellable object, 2746 * %NULL to ignore 2747 * callback = a #GAsyncReadyCallback to call 2748 * when the request is satisfied 2749 * userData = the data to pass to callback function 2750 */ 2751 public void readAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2752 { 2753 g_file_read_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2754 } 2755 2756 /** 2757 * Finishes an asynchronous file read operation started with 2758 * g_file_read_async(). 2759 * 2760 * Params: 2761 * res = a #GAsyncResult 2762 * 2763 * Return: a #GFileInputStream or %NULL on error. 2764 * Free the returned object with g_object_unref(). 2765 * 2766 * Throws: GException on failure. 2767 */ 2768 public FileInputStream readFinish(AsyncResultIF res) 2769 { 2770 GError* err = null; 2771 2772 auto p = g_file_read_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2773 2774 if (err !is null) 2775 { 2776 throw new GException( new ErrorG(err) ); 2777 } 2778 2779 if(p is null) 2780 { 2781 return null; 2782 } 2783 2784 return ObjectG.getDObject!(FileInputStream)(cast(GFileInputStream*) p, true); 2785 } 2786 2787 /** 2788 * Returns an output stream for overwriting the file, possibly 2789 * creating a backup copy of the file first. If the file doesn't exist, 2790 * it will be created. 2791 * 2792 * This will try to replace the file in the safest way possible so 2793 * that any errors during the writing will not affect an already 2794 * existing copy of the file. For instance, for local files it 2795 * may write to a temporary file and then atomically rename over 2796 * the destination when the stream is closed. 2797 * 2798 * By default files created are generally readable by everyone, 2799 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file 2800 * will be made readable only to the current user, to the level that 2801 * is supported on the target filesystem. 2802 * 2803 * If @cancellable is not %NULL, then the operation can be cancelled 2804 * by triggering the cancellable object from another thread. If the 2805 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2806 * returned. 2807 * 2808 * If you pass in a non-%NULL @etag value and @file already exists, then 2809 * this value is compared to the current entity tag of the file, and if 2810 * they differ an %G_IO_ERROR_WRONG_ETAG error is returned. This 2811 * generally means that the file has been changed since you last read 2812 * it. You can get the new etag from g_file_output_stream_get_etag() 2813 * after you've finished writing and closed the #GFileOutputStream. When 2814 * you load a new file you can use g_file_input_stream_query_info() to 2815 * get the etag of the file. 2816 * 2817 * If @make_backup is %TRUE, this function will attempt to make a 2818 * backup of the current file before overwriting it. If this fails 2819 * a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you 2820 * want to replace anyway, try again with @make_backup set to %FALSE. 2821 * 2822 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will 2823 * be returned, and if the file is some other form of non-regular file 2824 * then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some 2825 * file systems don't allow all file names, and may return an 2826 * %G_IO_ERROR_INVALID_FILENAME error, and if the name is to long 2827 * %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are 2828 * possible too, and depend on what kind of filesystem the file is on. 2829 * 2830 * Params: 2831 * etag = an optional [entity tag][gfile-etag] 2832 * for the current #GFile, or #NULL to ignore 2833 * makeBackup = %TRUE if a backup should be created 2834 * flags = a set of #GFileCreateFlags 2835 * cancellable = optional #GCancellable object, 2836 * %NULL to ignore 2837 * 2838 * Return: a #GFileOutputStream or %NULL on error. 2839 * Free the returned object with g_object_unref(). 2840 * 2841 * Throws: GException on failure. 2842 */ 2843 public FileOutputStream replace(string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable) 2844 { 2845 GError* err = null; 2846 2847 auto p = g_file_replace(getFileStruct(), Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2848 2849 if (err !is null) 2850 { 2851 throw new GException( new ErrorG(err) ); 2852 } 2853 2854 if(p is null) 2855 { 2856 return null; 2857 } 2858 2859 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 2860 } 2861 2862 /** 2863 * Asynchronously overwrites the file, replacing the contents, 2864 * possibly creating a backup copy of the file first. 2865 * 2866 * For more details, see g_file_replace() which is 2867 * the synchronous version of this call. 2868 * 2869 * When the operation is finished, @callback will be called. 2870 * You can then call g_file_replace_finish() to get the result 2871 * of the operation. 2872 * 2873 * Params: 2874 * etag = an [entity tag][gfile-etag] for the current #GFile, 2875 * or %NULL to ignore 2876 * makeBackup = %TRUE if a backup should be created 2877 * flags = a set of #GFileCreateFlags 2878 * ioPriority = the [I/O priority][io-priority] of the request 2879 * cancellable = optional #GCancellable object, 2880 * %NULL to ignore 2881 * callback = a #GAsyncReadyCallback to call 2882 * when the request is satisfied 2883 * userData = the data to pass to callback function 2884 */ 2885 public void replaceAsync(string etag, bool makeBackup, GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2886 { 2887 g_file_replace_async(getFileStruct(), Str.toStringz(etag), makeBackup, flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2888 } 2889 2890 /** 2891 * Replaces the contents of @file with @contents of @length bytes. 2892 * 2893 * If @etag is specified (not %NULL), any existing file must have that etag, 2894 * or the error %G_IO_ERROR_WRONG_ETAG will be returned. 2895 * 2896 * If @make_backup is %TRUE, this function will attempt to make a backup 2897 * of @file. Internally, it uses g_file_replace(), so will try to replace the 2898 * file contents in the safest way possible. For example, atomic renames are 2899 * used when replacing local files’ contents. 2900 * 2901 * If @cancellable is not %NULL, then the operation can be cancelled by 2902 * triggering the cancellable object from another thread. If the operation 2903 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2904 * 2905 * The returned @new_etag can be used to verify that the file hasn't 2906 * changed the next time it is saved over. 2907 * 2908 * Params: 2909 * contents = a string containing the new contents for @file 2910 * length = the length of @contents in bytes 2911 * etag = the old [entity-tag][gfile-etag] for the document, 2912 * or %NULL 2913 * makeBackup = %TRUE if a backup should be created 2914 * flags = a set of #GFileCreateFlags 2915 * newEtag = a location to a new [entity tag][gfile-etag] 2916 * for the document. This should be freed with g_free() when no longer 2917 * needed, or %NULL 2918 * cancellable = optional #GCancellable object, %NULL to ignore 2919 * 2920 * Return: %TRUE if successful. If an error has occurred, this function 2921 * will return %FALSE and set @error appropriately if present. 2922 * 2923 * Throws: GException on failure. 2924 */ 2925 public bool replaceContents(string contents, string etag, bool makeBackup, GFileCreateFlags flags, out string newEtag, Cancellable cancellable) 2926 { 2927 char* outnewEtag = null; 2928 GError* err = null; 2929 2930 auto p = g_file_replace_contents(getFileStruct(), Str.toStringz(contents), cast(size_t)contents.length, Str.toStringz(etag), makeBackup, flags, &outnewEtag, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 2931 2932 if (err !is null) 2933 { 2934 throw new GException( new ErrorG(err) ); 2935 } 2936 2937 newEtag = Str.toString(outnewEtag); 2938 2939 return p; 2940 } 2941 2942 /** 2943 * Starts an asynchronous replacement of @file with the given 2944 * @contents of @length bytes. @etag will replace the document's 2945 * current entity tag. 2946 * 2947 * When this operation has completed, @callback will be called with 2948 * @user_user data, and the operation can be finalized with 2949 * g_file_replace_contents_finish(). 2950 * 2951 * If @cancellable is not %NULL, then the operation can be cancelled by 2952 * triggering the cancellable object from another thread. If the operation 2953 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2954 * 2955 * If @make_backup is %TRUE, this function will attempt to 2956 * make a backup of @file. 2957 * 2958 * Note that no copy of @content will be made, so it must stay valid 2959 * until @callback is called. See g_file_replace_contents_bytes_async() 2960 * for a #GBytes version that will automatically hold a reference to the 2961 * contents (without copying) for the duration of the call. 2962 * 2963 * Params: 2964 * contents = string of contents to replace the file with 2965 * length = the length of @contents in bytes 2966 * etag = a new [entity tag][gfile-etag] for the @file, or %NULL 2967 * makeBackup = %TRUE if a backup should be created 2968 * flags = a set of #GFileCreateFlags 2969 * cancellable = optional #GCancellable object, %NULL to ignore 2970 * callback = a #GAsyncReadyCallback to call when the request is satisfied 2971 * userData = the data to pass to callback function 2972 */ 2973 public void replaceContentsAsync(string contents, string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2974 { 2975 g_file_replace_contents_async(getFileStruct(), Str.toStringz(contents), cast(size_t)contents.length, Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2976 } 2977 2978 /** 2979 * Same as g_file_replace_contents_async() but takes a #GBytes input instead. 2980 * This function will keep a ref on @contents until the operation is done. 2981 * Unlike g_file_replace_contents_async() this allows forgetting about the 2982 * content without waiting for the callback. 2983 * 2984 * When this operation has completed, @callback will be called with 2985 * @user_user data, and the operation can be finalized with 2986 * g_file_replace_contents_finish(). 2987 * 2988 * Params: 2989 * contents = a #GBytes 2990 * etag = a new [entity tag][gfile-etag] for the @file, or %NULL 2991 * makeBackup = %TRUE if a backup should be created 2992 * flags = a set of #GFileCreateFlags 2993 * cancellable = optional #GCancellable object, %NULL to ignore 2994 * callback = a #GAsyncReadyCallback to call when the request is satisfied 2995 * userData = the data to pass to callback function 2996 * 2997 * Since: 2.40 2998 */ 2999 public void replaceContentsBytesAsync(Bytes contents, string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3000 { 3001 g_file_replace_contents_bytes_async(getFileStruct(), (contents is null) ? null : contents.getBytesStruct(), Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3002 } 3003 3004 /** 3005 * Finishes an asynchronous replace of the given @file. See 3006 * g_file_replace_contents_async(). Sets @new_etag to the new entity 3007 * tag for the document, if present. 3008 * 3009 * Params: 3010 * res = a #GAsyncResult 3011 * newEtag = a location of a new [entity tag][gfile-etag] 3012 * for the document. This should be freed with g_free() when it is no 3013 * longer needed, or %NULL 3014 * 3015 * Return: %TRUE on success, %FALSE on failure. 3016 * 3017 * Throws: GException on failure. 3018 */ 3019 public bool replaceContentsFinish(AsyncResultIF res, out string newEtag) 3020 { 3021 char* outnewEtag = null; 3022 GError* err = null; 3023 3024 auto p = g_file_replace_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outnewEtag, &err) != 0; 3025 3026 if (err !is null) 3027 { 3028 throw new GException( new ErrorG(err) ); 3029 } 3030 3031 newEtag = Str.toString(outnewEtag); 3032 3033 return p; 3034 } 3035 3036 /** 3037 * Finishes an asynchronous file replace operation started with 3038 * g_file_replace_async(). 3039 * 3040 * Params: 3041 * res = a #GAsyncResult 3042 * 3043 * Return: a #GFileOutputStream, or %NULL on error. 3044 * Free the returned object with g_object_unref(). 3045 * 3046 * Throws: GException on failure. 3047 */ 3048 public FileOutputStream replaceFinish(AsyncResultIF res) 3049 { 3050 GError* err = null; 3051 3052 auto p = g_file_replace_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3053 3054 if (err !is null) 3055 { 3056 throw new GException( new ErrorG(err) ); 3057 } 3058 3059 if(p is null) 3060 { 3061 return null; 3062 } 3063 3064 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 3065 } 3066 3067 /** 3068 * Returns an output stream for overwriting the file in readwrite mode, 3069 * possibly creating a backup copy of the file first. If the file doesn't 3070 * exist, it will be created. 3071 * 3072 * For details about the behaviour, see g_file_replace() which does the 3073 * same thing but returns an output stream only. 3074 * 3075 * Note that in many non-local file cases read and write streams are not 3076 * supported, so make sure you really need to do read and write streaming, 3077 * rather than just opening for reading or writing. 3078 * 3079 * Params: 3080 * etag = an optional [entity tag][gfile-etag] 3081 * for the current #GFile, or #NULL to ignore 3082 * makeBackup = %TRUE if a backup should be created 3083 * flags = a set of #GFileCreateFlags 3084 * cancellable = optional #GCancellable object, 3085 * %NULL to ignore 3086 * 3087 * Return: a #GFileIOStream or %NULL on error. 3088 * Free the returned object with g_object_unref(). 3089 * 3090 * Since: 2.22 3091 * 3092 * Throws: GException on failure. 3093 */ 3094 public FileIOStream replaceReadwrite(string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable) 3095 { 3096 GError* err = null; 3097 3098 auto p = g_file_replace_readwrite(getFileStruct(), Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 3099 3100 if (err !is null) 3101 { 3102 throw new GException( new ErrorG(err) ); 3103 } 3104 3105 if(p is null) 3106 { 3107 return null; 3108 } 3109 3110 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 3111 } 3112 3113 /** 3114 * Asynchronously overwrites the file in read-write mode, 3115 * replacing the contents, possibly creating a backup copy 3116 * of the file first. 3117 * 3118 * For more details, see g_file_replace_readwrite() which is 3119 * the synchronous version of this call. 3120 * 3121 * When the operation is finished, @callback will be called. 3122 * You can then call g_file_replace_readwrite_finish() to get 3123 * the result of the operation. 3124 * 3125 * Params: 3126 * etag = an [entity tag][gfile-etag] for the current #GFile, 3127 * or %NULL to ignore 3128 * makeBackup = %TRUE if a backup should be created 3129 * flags = a set of #GFileCreateFlags 3130 * ioPriority = the [I/O priority][io-priority] of the request 3131 * cancellable = optional #GCancellable object, 3132 * %NULL to ignore 3133 * callback = a #GAsyncReadyCallback to call 3134 * when the request is satisfied 3135 * userData = the data to pass to callback function 3136 * 3137 * Since: 2.22 3138 */ 3139 public void replaceReadwriteAsync(string etag, bool makeBackup, GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3140 { 3141 g_file_replace_readwrite_async(getFileStruct(), Str.toStringz(etag), makeBackup, flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3142 } 3143 3144 /** 3145 * Finishes an asynchronous file replace operation started with 3146 * g_file_replace_readwrite_async(). 3147 * 3148 * Params: 3149 * res = a #GAsyncResult 3150 * 3151 * Return: a #GFileIOStream, or %NULL on error. 3152 * Free the returned object with g_object_unref(). 3153 * 3154 * Since: 2.22 3155 * 3156 * Throws: GException on failure. 3157 */ 3158 public FileIOStream replaceReadwriteFinish(AsyncResultIF res) 3159 { 3160 GError* err = null; 3161 3162 auto p = g_file_replace_readwrite_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3163 3164 if (err !is null) 3165 { 3166 throw new GException( new ErrorG(err) ); 3167 } 3168 3169 if(p is null) 3170 { 3171 return null; 3172 } 3173 3174 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 3175 } 3176 3177 /** 3178 * Resolves a relative path for @file to an absolute path. 3179 * 3180 * This call does no blocking I/O. 3181 * 3182 * Params: 3183 * relativePath = a given relative path string 3184 * 3185 * Return: #GFile to the resolved path. 3186 * %NULL if @relative_path is %NULL or if @file is invalid. 3187 * Free the returned object with g_object_unref(). 3188 */ 3189 public FileIF resolveRelativePath(string relativePath) 3190 { 3191 auto p = g_file_resolve_relative_path(getFileStruct(), Str.toStringz(relativePath)); 3192 3193 if(p is null) 3194 { 3195 return null; 3196 } 3197 3198 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3199 } 3200 3201 /** 3202 * Sets an attribute in the file with attribute name @attribute to @value. 3203 * 3204 * Some attributes can be unset by setting @attribute to 3205 * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL. 3206 * 3207 * If @cancellable is not %NULL, then the operation can be cancelled by 3208 * triggering the cancellable object from another thread. If the operation 3209 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3210 * 3211 * Params: 3212 * attribute = a string containing the attribute's name 3213 * type = The type of the attribute 3214 * valueP = a pointer to the value (or the pointer 3215 * itself if the type is a pointer type) 3216 * flags = a set of #GFileQueryInfoFlags 3217 * cancellable = optional #GCancellable object, 3218 * %NULL to ignore 3219 * 3220 * Return: %TRUE if the attribute was set, %FALSE otherwise. 3221 * 3222 * Throws: GException on failure. 3223 */ 3224 public bool setAttribute(string attribute, GFileAttributeType type, void* valueP, GFileQueryInfoFlags flags, Cancellable cancellable) 3225 { 3226 GError* err = null; 3227 3228 auto p = g_file_set_attribute(getFileStruct(), Str.toStringz(attribute), type, valueP, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3229 3230 if (err !is null) 3231 { 3232 throw new GException( new ErrorG(err) ); 3233 } 3234 3235 return p; 3236 } 3237 3238 /** 3239 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value. 3240 * If @attribute is of a different type, this operation will fail, 3241 * returning %FALSE. 3242 * 3243 * If @cancellable is not %NULL, then the operation can be cancelled by 3244 * triggering the cancellable object from another thread. If the operation 3245 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3246 * 3247 * Params: 3248 * attribute = a string containing the attribute's name 3249 * value = a string containing the attribute's new value 3250 * flags = a #GFileQueryInfoFlags 3251 * cancellable = optional #GCancellable object, 3252 * %NULL to ignore 3253 * 3254 * Return: %TRUE if the @attribute was successfully set to @value 3255 * in the @file, %FALSE otherwise. 3256 * 3257 * Throws: GException on failure. 3258 */ 3259 public bool setAttributeByteString(string attribute, string value, GFileQueryInfoFlags flags, Cancellable cancellable) 3260 { 3261 GError* err = null; 3262 3263 auto p = g_file_set_attribute_byte_string(getFileStruct(), Str.toStringz(attribute), Str.toStringz(value), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3264 3265 if (err !is null) 3266 { 3267 throw new GException( new ErrorG(err) ); 3268 } 3269 3270 return p; 3271 } 3272 3273 /** 3274 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value. 3275 * If @attribute is of a different type, this operation will fail. 3276 * 3277 * If @cancellable is not %NULL, then the operation can be cancelled by 3278 * triggering the cancellable object from another thread. If the operation 3279 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3280 * 3281 * Params: 3282 * attribute = a string containing the attribute's name 3283 * value = a #gint32 containing the attribute's new value 3284 * flags = a #GFileQueryInfoFlags 3285 * cancellable = optional #GCancellable object, 3286 * %NULL to ignore 3287 * 3288 * Return: %TRUE if the @attribute was successfully set to @value 3289 * in the @file, %FALSE otherwise. 3290 * 3291 * Throws: GException on failure. 3292 */ 3293 public bool setAttributeInt32(string attribute, int value, GFileQueryInfoFlags flags, Cancellable cancellable) 3294 { 3295 GError* err = null; 3296 3297 auto p = g_file_set_attribute_int32(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3298 3299 if (err !is null) 3300 { 3301 throw new GException( new ErrorG(err) ); 3302 } 3303 3304 return p; 3305 } 3306 3307 /** 3308 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value. 3309 * If @attribute is of a different type, this operation will fail. 3310 * 3311 * If @cancellable is not %NULL, then the operation can be cancelled by 3312 * triggering the cancellable object from another thread. If the operation 3313 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3314 * 3315 * Params: 3316 * attribute = a string containing the attribute's name 3317 * value = a #guint64 containing the attribute's new value 3318 * flags = a #GFileQueryInfoFlags 3319 * cancellable = optional #GCancellable object, 3320 * %NULL to ignore 3321 * 3322 * Return: %TRUE if the @attribute was successfully set, %FALSE otherwise. 3323 * 3324 * Throws: GException on failure. 3325 */ 3326 public bool setAttributeInt64(string attribute, long value, GFileQueryInfoFlags flags, Cancellable cancellable) 3327 { 3328 GError* err = null; 3329 3330 auto p = g_file_set_attribute_int64(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3331 3332 if (err !is null) 3333 { 3334 throw new GException( new ErrorG(err) ); 3335 } 3336 3337 return p; 3338 } 3339 3340 /** 3341 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value. 3342 * If @attribute is of a different type, this operation will fail. 3343 * 3344 * If @cancellable is not %NULL, then the operation can be cancelled by 3345 * triggering the cancellable object from another thread. If the operation 3346 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3347 * 3348 * Params: 3349 * attribute = a string containing the attribute's name 3350 * value = a string containing the attribute's value 3351 * flags = #GFileQueryInfoFlags 3352 * cancellable = optional #GCancellable object, 3353 * %NULL to ignore 3354 * 3355 * Return: %TRUE if the @attribute was successfully set, %FALSE otherwise. 3356 * 3357 * Throws: GException on failure. 3358 */ 3359 public bool setAttributeString(string attribute, string value, GFileQueryInfoFlags flags, Cancellable cancellable) 3360 { 3361 GError* err = null; 3362 3363 auto p = g_file_set_attribute_string(getFileStruct(), Str.toStringz(attribute), Str.toStringz(value), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3364 3365 if (err !is null) 3366 { 3367 throw new GException( new ErrorG(err) ); 3368 } 3369 3370 return p; 3371 } 3372 3373 /** 3374 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value. 3375 * If @attribute is of a different type, this operation will fail. 3376 * 3377 * If @cancellable is not %NULL, then the operation can be cancelled by 3378 * triggering the cancellable object from another thread. If the operation 3379 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3380 * 3381 * Params: 3382 * attribute = a string containing the attribute's name 3383 * value = a #guint32 containing the attribute's new value 3384 * flags = a #GFileQueryInfoFlags 3385 * cancellable = optional #GCancellable object, 3386 * %NULL to ignore 3387 * 3388 * Return: %TRUE if the @attribute was successfully set to @value 3389 * in the @file, %FALSE otherwise. 3390 * 3391 * Throws: GException on failure. 3392 */ 3393 public bool setAttributeUint32(string attribute, uint value, GFileQueryInfoFlags flags, Cancellable cancellable) 3394 { 3395 GError* err = null; 3396 3397 auto p = g_file_set_attribute_uint32(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3398 3399 if (err !is null) 3400 { 3401 throw new GException( new ErrorG(err) ); 3402 } 3403 3404 return p; 3405 } 3406 3407 /** 3408 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value. 3409 * If @attribute is of a different type, this operation will fail. 3410 * 3411 * If @cancellable is not %NULL, then the operation can be cancelled by 3412 * triggering the cancellable object from another thread. If the operation 3413 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3414 * 3415 * Params: 3416 * attribute = a string containing the attribute's name 3417 * value = a #guint64 containing the attribute's new value 3418 * flags = a #GFileQueryInfoFlags 3419 * cancellable = optional #GCancellable object, 3420 * %NULL to ignore 3421 * 3422 * Return: %TRUE if the @attribute was successfully set to @value 3423 * in the @file, %FALSE otherwise. 3424 * 3425 * Throws: GException on failure. 3426 */ 3427 public bool setAttributeUint64(string attribute, ulong value, GFileQueryInfoFlags flags, Cancellable cancellable) 3428 { 3429 GError* err = null; 3430 3431 auto p = g_file_set_attribute_uint64(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3432 3433 if (err !is null) 3434 { 3435 throw new GException( new ErrorG(err) ); 3436 } 3437 3438 return p; 3439 } 3440 3441 /** 3442 * Asynchronously sets the attributes of @file with @info. 3443 * 3444 * For more details, see g_file_set_attributes_from_info(), 3445 * which is the synchronous version of this call. 3446 * 3447 * When the operation is finished, @callback will be called. 3448 * You can then call g_file_set_attributes_finish() to get 3449 * the result of the operation. 3450 * 3451 * Params: 3452 * info = a #GFileInfo 3453 * flags = a #GFileQueryInfoFlags 3454 * ioPriority = the [I/O priority][io-priority] of the request 3455 * cancellable = optional #GCancellable object, 3456 * %NULL to ignore 3457 * callback = a #GAsyncReadyCallback 3458 * userData = a #gpointer 3459 */ 3460 public void setAttributesAsync(FileInfo info, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3461 { 3462 g_file_set_attributes_async(getFileStruct(), (info is null) ? null : info.getFileInfoStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3463 } 3464 3465 /** 3466 * Finishes setting an attribute started in g_file_set_attributes_async(). 3467 * 3468 * Params: 3469 * result = a #GAsyncResult 3470 * info = a #GFileInfo 3471 * 3472 * Return: %TRUE if the attributes were set correctly, %FALSE otherwise. 3473 * 3474 * Throws: GException on failure. 3475 */ 3476 public bool setAttributesFinish(AsyncResultIF result, out FileInfo info) 3477 { 3478 GFileInfo* outinfo = null; 3479 GError* err = null; 3480 3481 auto p = g_file_set_attributes_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &outinfo, &err) != 0; 3482 3483 if (err !is null) 3484 { 3485 throw new GException( new ErrorG(err) ); 3486 } 3487 3488 info = ObjectG.getDObject!(FileInfo)(outinfo); 3489 3490 return p; 3491 } 3492 3493 /** 3494 * Tries to set all attributes in the #GFileInfo on the target 3495 * values, not stopping on the first error. 3496 * 3497 * If there is any error during this operation then @error will 3498 * be set to the first error. Error on particular fields are flagged 3499 * by setting the "status" field in the attribute value to 3500 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can 3501 * also detect further errors. 3502 * 3503 * If @cancellable is not %NULL, then the operation can be cancelled by 3504 * triggering the cancellable object from another thread. If the operation 3505 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3506 * 3507 * Params: 3508 * info = a #GFileInfo 3509 * flags = #GFileQueryInfoFlags 3510 * cancellable = optional #GCancellable object, 3511 * %NULL to ignore 3512 * 3513 * Return: %FALSE if there was any error, %TRUE otherwise. 3514 * 3515 * Throws: GException on failure. 3516 */ 3517 public bool setAttributesFromInfo(FileInfo info, GFileQueryInfoFlags flags, Cancellable cancellable) 3518 { 3519 GError* err = null; 3520 3521 auto p = g_file_set_attributes_from_info(getFileStruct(), (info is null) ? null : info.getFileInfoStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3522 3523 if (err !is null) 3524 { 3525 throw new GException( new ErrorG(err) ); 3526 } 3527 3528 return p; 3529 } 3530 3531 /** 3532 * Renames @file to the specified display name. 3533 * 3534 * The display name is converted from UTF-8 to the correct encoding 3535 * for the target filesystem if possible and the @file is renamed to this. 3536 * 3537 * If you want to implement a rename operation in the user interface the 3538 * edit name (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the 3539 * initial value in the rename widget, and then the result after editing 3540 * should be passed to g_file_set_display_name(). 3541 * 3542 * On success the resulting converted filename is returned. 3543 * 3544 * If @cancellable is not %NULL, then the operation can be cancelled by 3545 * triggering the cancellable object from another thread. If the operation 3546 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3547 * 3548 * Params: 3549 * displayName = a string 3550 * cancellable = optional #GCancellable object, 3551 * %NULL to ignore 3552 * 3553 * Return: a #GFile specifying what @file was renamed to, 3554 * or %NULL if there was an error. 3555 * Free the returned object with g_object_unref(). 3556 * 3557 * Throws: GException on failure. 3558 */ 3559 public FileIF setDisplayName(string displayName, Cancellable cancellable) 3560 { 3561 GError* err = null; 3562 3563 auto p = g_file_set_display_name(getFileStruct(), Str.toStringz(displayName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 3564 3565 if (err !is null) 3566 { 3567 throw new GException( new ErrorG(err) ); 3568 } 3569 3570 if(p is null) 3571 { 3572 return null; 3573 } 3574 3575 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3576 } 3577 3578 /** 3579 * Asynchronously sets the display name for a given #GFile. 3580 * 3581 * For more details, see g_file_set_display_name() which is 3582 * the synchronous version of this call. 3583 * 3584 * When the operation is finished, @callback will be called. 3585 * You can then call g_file_set_display_name_finish() to get 3586 * the result of the operation. 3587 * 3588 * Params: 3589 * displayName = a string 3590 * ioPriority = the [I/O priority][io-priority] of the request 3591 * cancellable = optional #GCancellable object, 3592 * %NULL to ignore 3593 * callback = a #GAsyncReadyCallback to call 3594 * when the request is satisfied 3595 * userData = the data to pass to callback function 3596 */ 3597 public void setDisplayNameAsync(string displayName, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3598 { 3599 g_file_set_display_name_async(getFileStruct(), Str.toStringz(displayName), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3600 } 3601 3602 /** 3603 * Finishes setting a display name started with 3604 * g_file_set_display_name_async(). 3605 * 3606 * Params: 3607 * res = a #GAsyncResult 3608 * 3609 * Return: a #GFile or %NULL on error. 3610 * Free the returned object with g_object_unref(). 3611 * 3612 * Throws: GException on failure. 3613 */ 3614 public FileIF setDisplayNameFinish(AsyncResultIF res) 3615 { 3616 GError* err = null; 3617 3618 auto p = g_file_set_display_name_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3619 3620 if (err !is null) 3621 { 3622 throw new GException( new ErrorG(err) ); 3623 } 3624 3625 if(p is null) 3626 { 3627 return null; 3628 } 3629 3630 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3631 } 3632 3633 /** 3634 * Starts a file of type #G_FILE_TYPE_MOUNTABLE. 3635 * Using @start_operation, you can request callbacks when, for instance, 3636 * passwords are needed during authentication. 3637 * 3638 * If @cancellable is not %NULL, then the operation can be cancelled by 3639 * triggering the cancellable object from another thread. If the operation 3640 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3641 * 3642 * When the operation is finished, @callback will be called. 3643 * You can then call g_file_mount_mountable_finish() to get 3644 * the result of the operation. 3645 * 3646 * Params: 3647 * flags = flags affecting the operation 3648 * startOperation = a #GMountOperation, or %NULL to avoid user interaction 3649 * cancellable = optional #GCancellable object, %NULL to ignore 3650 * callback = a #GAsyncReadyCallback to call when the request is satisfied, or %NULL 3651 * userData = the data to pass to callback function 3652 * 3653 * Since: 2.22 3654 */ 3655 public void startMountable(GDriveStartFlags flags, MountOperation startOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3656 { 3657 g_file_start_mountable(getFileStruct(), flags, (startOperation is null) ? null : startOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3658 } 3659 3660 /** 3661 * Finishes a start operation. See g_file_start_mountable() for details. 3662 * 3663 * Finish an asynchronous start operation that was started 3664 * with g_file_start_mountable(). 3665 * 3666 * Params: 3667 * result = a #GAsyncResult 3668 * 3669 * Return: %TRUE if the operation finished successfully. %FALSE 3670 * otherwise. 3671 * 3672 * Since: 2.22 3673 * 3674 * Throws: GException on failure. 3675 */ 3676 public bool startMountableFinish(AsyncResultIF result) 3677 { 3678 GError* err = null; 3679 3680 auto p = g_file_start_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3681 3682 if (err !is null) 3683 { 3684 throw new GException( new ErrorG(err) ); 3685 } 3686 3687 return p; 3688 } 3689 3690 /** 3691 * Stops a file of type #G_FILE_TYPE_MOUNTABLE. 3692 * 3693 * If @cancellable is not %NULL, then the operation can be cancelled by 3694 * triggering the cancellable object from another thread. If the operation 3695 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3696 * 3697 * When the operation is finished, @callback will be called. 3698 * You can then call g_file_stop_mountable_finish() to get 3699 * the result of the operation. 3700 * 3701 * Params: 3702 * flags = flags affecting the operation 3703 * mountOperation = a #GMountOperation, 3704 * or %NULL to avoid user interaction. 3705 * cancellable = optional #GCancellable object, 3706 * %NULL to ignore 3707 * callback = a #GAsyncReadyCallback to call 3708 * when the request is satisfied, or %NULL 3709 * userData = the data to pass to callback function 3710 * 3711 * Since: 2.22 3712 */ 3713 public void stopMountable(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3714 { 3715 g_file_stop_mountable(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3716 } 3717 3718 /** 3719 * Finishes an stop operation, see g_file_stop_mountable() for details. 3720 * 3721 * Finish an asynchronous stop operation that was started 3722 * with g_file_stop_mountable(). 3723 * 3724 * Params: 3725 * result = a #GAsyncResult 3726 * 3727 * Return: %TRUE if the operation finished successfully. 3728 * %FALSE otherwise. 3729 * 3730 * Since: 2.22 3731 * 3732 * Throws: GException on failure. 3733 */ 3734 public bool stopMountableFinish(AsyncResultIF result) 3735 { 3736 GError* err = null; 3737 3738 auto p = g_file_stop_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3739 3740 if (err !is null) 3741 { 3742 throw new GException( new ErrorG(err) ); 3743 } 3744 3745 return p; 3746 } 3747 3748 /** 3749 * Checks if @file supports 3750 * [thread-default contexts][g-main-context-push-thread-default-context]. 3751 * If this returns %FALSE, you cannot perform asynchronous operations on 3752 * @file in a thread that has a thread-default context. 3753 * 3754 * Return: Whether or not @file supports thread-default contexts. 3755 * 3756 * Since: 2.22 3757 */ 3758 public bool supportsThreadContexts() 3759 { 3760 return g_file_supports_thread_contexts(getFileStruct()) != 0; 3761 } 3762 3763 /** 3764 * Sends @file to the "Trashcan", if possible. This is similar to 3765 * deleting it, but the user can recover it before emptying the trashcan. 3766 * Not all file systems support trashing, so this call can return the 3767 * %G_IO_ERROR_NOT_SUPPORTED error. 3768 * 3769 * If @cancellable is not %NULL, then the operation can be cancelled by 3770 * triggering the cancellable object from another thread. If the operation 3771 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3772 * 3773 * Params: 3774 * cancellable = optional #GCancellable object, 3775 * %NULL to ignore 3776 * 3777 * Return: %TRUE on successful trash, %FALSE otherwise. 3778 * 3779 * Throws: GException on failure. 3780 */ 3781 public bool trash(Cancellable cancellable) 3782 { 3783 GError* err = null; 3784 3785 auto p = g_file_trash(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3786 3787 if (err !is null) 3788 { 3789 throw new GException( new ErrorG(err) ); 3790 } 3791 3792 return p; 3793 } 3794 3795 /** 3796 * Asynchronously sends @file to the Trash location, if possible. 3797 * 3798 * Params: 3799 * ioPriority = the [I/O priority][io-priority] of the request 3800 * cancellable = optional #GCancellable object, 3801 * %NULL to ignore 3802 * callback = a #GAsyncReadyCallback to call 3803 * when the request is satisfied 3804 * userData = the data to pass to callback function 3805 * 3806 * Since: 2.38 3807 */ 3808 public void trashAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3809 { 3810 g_file_trash_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3811 } 3812 3813 /** 3814 * Finishes an asynchronous file trashing operation, started with 3815 * g_file_trash_async(). 3816 * 3817 * Params: 3818 * result = a #GAsyncResult 3819 * 3820 * Return: %TRUE on successful trash, %FALSE otherwise. 3821 * 3822 * Since: 2.38 3823 * 3824 * Throws: GException on failure. 3825 */ 3826 public bool trashFinish(AsyncResultIF result) 3827 { 3828 GError* err = null; 3829 3830 auto p = g_file_trash_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3831 3832 if (err !is null) 3833 { 3834 throw new GException( new ErrorG(err) ); 3835 } 3836 3837 return p; 3838 } 3839 3840 /** 3841 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE. 3842 * 3843 * If @cancellable is not %NULL, then the operation can be cancelled by 3844 * triggering the cancellable object from another thread. If the operation 3845 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3846 * 3847 * When the operation is finished, @callback will be called. 3848 * You can then call g_file_unmount_mountable_finish() to get 3849 * the result of the operation. 3850 * 3851 * Deprecated: Use g_file_unmount_mountable_with_operation() instead. 3852 * 3853 * Params: 3854 * flags = flags affecting the operation 3855 * cancellable = optional #GCancellable object, 3856 * %NULL to ignore 3857 * callback = a #GAsyncReadyCallback to call 3858 * when the request is satisfied, or %NULL 3859 * userData = the data to pass to callback function 3860 */ 3861 public void unmountMountable(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3862 { 3863 g_file_unmount_mountable(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3864 } 3865 3866 /** 3867 * Finishes an unmount operation, see g_file_unmount_mountable() for details. 3868 * 3869 * Finish an asynchronous unmount operation that was started 3870 * with g_file_unmount_mountable(). 3871 * 3872 * Deprecated: Use g_file_unmount_mountable_with_operation_finish() 3873 * instead. 3874 * 3875 * Params: 3876 * result = a #GAsyncResult 3877 * 3878 * Return: %TRUE if the operation finished successfully. 3879 * %FALSE otherwise. 3880 * 3881 * Throws: GException on failure. 3882 */ 3883 public bool unmountMountableFinish(AsyncResultIF result) 3884 { 3885 GError* err = null; 3886 3887 auto p = g_file_unmount_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3888 3889 if (err !is null) 3890 { 3891 throw new GException( new ErrorG(err) ); 3892 } 3893 3894 return p; 3895 } 3896 3897 /** 3898 * Unmounts a file of type #G_FILE_TYPE_MOUNTABLE. 3899 * 3900 * If @cancellable is not %NULL, then the operation can be cancelled by 3901 * triggering the cancellable object from another thread. If the operation 3902 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3903 * 3904 * When the operation is finished, @callback will be called. 3905 * You can then call g_file_unmount_mountable_finish() to get 3906 * the result of the operation. 3907 * 3908 * Params: 3909 * flags = flags affecting the operation 3910 * mountOperation = a #GMountOperation, 3911 * or %NULL to avoid user interaction 3912 * cancellable = optional #GCancellable object, 3913 * %NULL to ignore 3914 * callback = a #GAsyncReadyCallback to call 3915 * when the request is satisfied, or %NULL 3916 * userData = the data to pass to callback function 3917 * 3918 * Since: 2.22 3919 */ 3920 public void unmountMountableWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3921 { 3922 g_file_unmount_mountable_with_operation(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3923 } 3924 3925 /** 3926 * Finishes an unmount operation, 3927 * see g_file_unmount_mountable_with_operation() for details. 3928 * 3929 * Finish an asynchronous unmount operation that was started 3930 * with g_file_unmount_mountable_with_operation(). 3931 * 3932 * Params: 3933 * result = a #GAsyncResult 3934 * 3935 * Return: %TRUE if the operation finished successfully. 3936 * %FALSE otherwise. 3937 * 3938 * Since: 2.22 3939 * 3940 * Throws: GException on failure. 3941 */ 3942 public bool unmountMountableWithOperationFinish(AsyncResultIF result) 3943 { 3944 GError* err = null; 3945 3946 auto p = g_file_unmount_mountable_with_operation_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3947 3948 if (err !is null) 3949 { 3950 throw new GException( new ErrorG(err) ); 3951 } 3952 3953 return p; 3954 } 3955 }