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