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