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