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