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. If non-%NULL, this is 1223 * guaranteed to be an absolute, canonical path. It might contain symlinks. 1224 * 1225 * This call does no blocking I/O. 1226 * 1227 * Return: string containing the #GFile's path, or %NULL 1228 * if no such path exists. The returned string should be freed 1229 * with g_free() when no longer needed. 1230 */ 1231 public string getPath() 1232 { 1233 return Str.toString(g_file_get_path(getFileStruct())); 1234 } 1235 1236 /** 1237 * Gets the path for @descendant relative to @parent. 1238 * 1239 * This call does no blocking I/O. 1240 * 1241 * Params: 1242 * descendant = input #GFile 1243 * 1244 * Return: string with the relative path from @descendant 1245 * to @parent, or %NULL if @descendant doesn't have @parent as 1246 * prefix. The returned string should be freed with g_free() when 1247 * no longer needed. 1248 */ 1249 public string getRelativePath(FileIF descendant) 1250 { 1251 return Str.toString(g_file_get_relative_path(getFileStruct(), (descendant is null) ? null : descendant.getFileStruct())); 1252 } 1253 1254 /** 1255 * Gets the URI for the @file. 1256 * 1257 * This call does no blocking I/O. 1258 * 1259 * Return: a string containing the #GFile's URI. 1260 * The returned string should be freed with g_free() 1261 * when no longer needed. 1262 */ 1263 public string getUri() 1264 { 1265 return Str.toString(g_file_get_uri(getFileStruct())); 1266 } 1267 1268 /** 1269 * Gets the URI scheme for a #GFile. 1270 * RFC 3986 decodes the scheme as: 1271 * |[ 1272 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] 1273 * ]| 1274 * Common schemes include "file", "http", "ftp", etc. 1275 * 1276 * This call does no blocking I/O. 1277 * 1278 * Return: a string containing the URI scheme for the given 1279 * #GFile. The returned string should be freed with g_free() 1280 * when no longer needed. 1281 */ 1282 public string getUriScheme() 1283 { 1284 return Str.toString(g_file_get_uri_scheme(getFileStruct())); 1285 } 1286 1287 /** 1288 * Checks if @file has a parent, and optionally, if it is @parent. 1289 * 1290 * If @parent is %NULL then this function returns %TRUE if @file has any 1291 * parent at all. If @parent is non-%NULL then %TRUE is only returned 1292 * if @file is an immediate child of @parent. 1293 * 1294 * Params: 1295 * parent = the parent to check for, or %NULL 1296 * 1297 * Return: %TRUE if @file is an immediate child of @parent (or any parent in 1298 * the case that @parent is %NULL). 1299 * 1300 * Since: 2.24 1301 */ 1302 public bool hasParent(FileIF parent) 1303 { 1304 return g_file_has_parent(getFileStruct(), (parent is null) ? null : parent.getFileStruct()) != 0; 1305 } 1306 1307 /** 1308 * Checks whether @file has the prefix specified by @prefix. 1309 * 1310 * In other words, if the names of initial elements of @file's 1311 * pathname match @prefix. Only full pathname elements are matched, 1312 * so a path like /foo is not considered a prefix of /foobar, only 1313 * of /foo/bar. 1314 * 1315 * A #GFile is not a prefix of itself. If you want to check for 1316 * equality, use g_file_equal(). 1317 * 1318 * This call does no I/O, as it works purely on names. As such it can 1319 * sometimes return %FALSE even if @file is inside a @prefix (from a 1320 * filesystem point of view), because the prefix of @file is an alias 1321 * of @prefix. 1322 * 1323 * Params: 1324 * prefix = input #GFile 1325 * 1326 * Return: %TRUE if the @files's parent, grandparent, etc is @prefix, 1327 * %FALSE otherwise. 1328 */ 1329 public bool hasPrefix(FileIF prefix) 1330 { 1331 return g_file_has_prefix(getFileStruct(), (prefix is null) ? null : prefix.getFileStruct()) != 0; 1332 } 1333 1334 /** 1335 * Checks to see if a #GFile has a given URI scheme. 1336 * 1337 * This call does no blocking I/O. 1338 * 1339 * Params: 1340 * uriScheme = a string containing a URI scheme 1341 * 1342 * Return: %TRUE if #GFile's backend supports the 1343 * given URI scheme, %FALSE if URI scheme is %NULL, 1344 * not supported, or #GFile is invalid. 1345 */ 1346 public bool hasUriScheme(string uriScheme) 1347 { 1348 return g_file_has_uri_scheme(getFileStruct(), Str.toStringz(uriScheme)) != 0; 1349 } 1350 1351 /** 1352 * Creates a hash value for a #GFile. 1353 * 1354 * This call does no blocking I/O. 1355 * 1356 * Return: 0 if @file is not a valid #GFile, otherwise an 1357 * integer that can be used as hash value for the #GFile. 1358 * This function is intended for easily hashing a #GFile to 1359 * add to a #GHashTable or similar data structure. 1360 */ 1361 public uint hash() 1362 { 1363 return g_file_hash(getFileStruct()); 1364 } 1365 1366 /** 1367 * Checks to see if a file is native to the platform. 1368 * 1369 * A native file s one expressed in the platform-native filename format, 1370 * e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local, 1371 * as it might be on a locally mounted remote filesystem. 1372 * 1373 * On some systems non-native files may be available using the native 1374 * filesystem via a userspace filesystem (FUSE), in these cases this call 1375 * will return %FALSE, but g_file_get_path() will still return a native path. 1376 * 1377 * This call does no blocking I/O. 1378 * 1379 * Return: %TRUE if @file is native 1380 */ 1381 public bool isNative() 1382 { 1383 return g_file_is_native(getFileStruct()) != 0; 1384 } 1385 1386 /** 1387 * Loads the content of the file into memory. The data is always 1388 * zero-terminated, but this is not included in the resultant @length. 1389 * The returned @content should be freed with g_free() when no longer 1390 * needed. 1391 * 1392 * If @cancellable is not %NULL, then the operation can be cancelled by 1393 * triggering the cancellable object from another thread. If the operation 1394 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1395 * 1396 * Params: 1397 * cancellable = optional #GCancellable object, %NULL to ignore 1398 * contents = a location to place the contents of the file 1399 * length = a location to place the length of the contents of the file, 1400 * or %NULL if the length is not needed 1401 * etagOut = a location to place the current entity tag for the file, 1402 * or %NULL if the entity tag is not needed 1403 * 1404 * Return: %TRUE if the @file's contents were successfully loaded. 1405 * %FALSE if there were errors. 1406 * 1407 * Throws: GException on failure. 1408 */ 1409 public bool loadContents(Cancellable cancellable, out string contents, out string etagOut) 1410 { 1411 char* outcontents = null; 1412 size_t length; 1413 char* outetagOut = null; 1414 GError* err = null; 1415 1416 auto p = g_file_load_contents(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1417 1418 if (err !is null) 1419 { 1420 throw new GException( new ErrorG(err) ); 1421 } 1422 1423 contents = Str.toString(outcontents, length); 1424 etagOut = Str.toString(outetagOut); 1425 1426 return p; 1427 } 1428 1429 /** 1430 * Starts an asynchronous load of the @file's contents. 1431 * 1432 * For more details, see g_file_load_contents() which is 1433 * the synchronous version of this call. 1434 * 1435 * When the load operation has completed, @callback will be called 1436 * with @user data. To finish the operation, call 1437 * g_file_load_contents_finish() with the #GAsyncResult returned by 1438 * the @callback. 1439 * 1440 * If @cancellable is not %NULL, then the operation can be cancelled by 1441 * triggering the cancellable object from another thread. If the operation 1442 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1443 * 1444 * Params: 1445 * cancellable = optional #GCancellable object, %NULL to ignore 1446 * callback = a #GAsyncReadyCallback to call when the request is satisfied 1447 * userData = the data to pass to callback function 1448 */ 1449 public void loadContentsAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1450 { 1451 g_file_load_contents_async(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1452 } 1453 1454 /** 1455 * Finishes an asynchronous load of the @file's contents. 1456 * The contents are placed in @contents, and @length is set to the 1457 * size of the @contents string. The @content should be freed with 1458 * g_free() when no longer needed. If @etag_out is present, it will be 1459 * set to the new entity tag for the @file. 1460 * 1461 * Params: 1462 * res = a #GAsyncResult 1463 * contents = a location to place the contents of the file 1464 * length = a location to place the length of the contents of the file, 1465 * or %NULL if the length is not needed 1466 * etagOut = a location to place the current entity tag for the file, 1467 * or %NULL if the entity tag is not needed 1468 * 1469 * Return: %TRUE if the load was successful. If %FALSE and @error is 1470 * present, it will be set appropriately. 1471 * 1472 * Throws: GException on failure. 1473 */ 1474 public bool loadContentsFinish(AsyncResultIF res, out string contents, out string etagOut) 1475 { 1476 char* outcontents = null; 1477 size_t length; 1478 char* outetagOut = null; 1479 GError* err = null; 1480 1481 auto p = g_file_load_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1482 1483 if (err !is null) 1484 { 1485 throw new GException( new ErrorG(err) ); 1486 } 1487 1488 contents = Str.toString(outcontents, length); 1489 etagOut = Str.toString(outetagOut); 1490 1491 return p; 1492 } 1493 1494 /** 1495 * Reads the partial contents of a file. A #GFileReadMoreCallback should 1496 * be used to stop reading from the file when appropriate, else this 1497 * function will behave exactly as g_file_load_contents_async(). This 1498 * operation can be finished by g_file_load_partial_contents_finish(). 1499 * 1500 * Users of this function should be aware that @user_data is passed to 1501 * both the @read_more_callback and the @callback. 1502 * 1503 * If @cancellable is not %NULL, then the operation can be cancelled by 1504 * triggering the cancellable object from another thread. If the operation 1505 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1506 * 1507 * Params: 1508 * cancellable = optional #GCancellable object, %NULL to ignore 1509 * readMoreCallback = a #GFileReadMoreCallback to receive partial data 1510 * and to specify whether further data should be read 1511 * callback = a #GAsyncReadyCallback to call when the request is satisfied 1512 * userData = the data to pass to the callback functions 1513 */ 1514 public void loadPartialContentsAsync(Cancellable cancellable, GFileReadMoreCallback readMoreCallback, GAsyncReadyCallback callback, void* userData) 1515 { 1516 g_file_load_partial_contents_async(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), readMoreCallback, callback, userData); 1517 } 1518 1519 /** 1520 * Finishes an asynchronous partial load operation that was started 1521 * with g_file_load_partial_contents_async(). The data is always 1522 * zero-terminated, but this is not included in the resultant @length. 1523 * The returned @content should be freed with g_free() when no longer 1524 * needed. 1525 * 1526 * Params: 1527 * res = a #GAsyncResult 1528 * contents = a location to place the contents of the file 1529 * length = a location to place the length of the contents of the file, 1530 * or %NULL if the length is not needed 1531 * etagOut = a location to place the current entity tag for the file, 1532 * or %NULL if the entity tag is not needed 1533 * 1534 * Return: %TRUE if the load was successful. If %FALSE and @error is 1535 * present, it will be set appropriately. 1536 * 1537 * Throws: GException on failure. 1538 */ 1539 public bool loadPartialContentsFinish(AsyncResultIF res, out string contents, out string etagOut) 1540 { 1541 char* outcontents = null; 1542 size_t length; 1543 char* outetagOut = null; 1544 GError* err = null; 1545 1546 auto p = g_file_load_partial_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outcontents, &length, &outetagOut, &err) != 0; 1547 1548 if (err !is null) 1549 { 1550 throw new GException( new ErrorG(err) ); 1551 } 1552 1553 contents = Str.toString(outcontents, length); 1554 etagOut = Str.toString(outetagOut); 1555 1556 return p; 1557 } 1558 1559 /** 1560 * Creates a directory. Note that this will only create a child directory 1561 * of the immediate parent directory of the path or URI given by the #GFile. 1562 * To recursively create directories, see g_file_make_directory_with_parents(). 1563 * This function will fail if the parent directory does not exist, setting 1564 * @error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support 1565 * creating directories, this function will fail, setting @error to 1566 * %G_IO_ERROR_NOT_SUPPORTED. 1567 * 1568 * For a local #GFile the newly created directory will have the default 1569 * (current) ownership and permissions of the current process. 1570 * 1571 * If @cancellable is not %NULL, then the operation can be cancelled by 1572 * triggering the cancellable object from another thread. If the operation 1573 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1574 * 1575 * Params: 1576 * cancellable = optional #GCancellable object, 1577 * %NULL to ignore 1578 * 1579 * Return: %TRUE on successful creation, %FALSE otherwise. 1580 * 1581 * Throws: GException on failure. 1582 */ 1583 public bool makeDirectory(Cancellable cancellable) 1584 { 1585 GError* err = null; 1586 1587 auto p = g_file_make_directory(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1588 1589 if (err !is null) 1590 { 1591 throw new GException( new ErrorG(err) ); 1592 } 1593 1594 return p; 1595 } 1596 1597 /** 1598 * Asynchronously creates a directory. 1599 * 1600 * Params: 1601 * ioPriority = the [I/O priority][io-priority] of the request 1602 * cancellable = optional #GCancellable object, 1603 * %NULL to ignore 1604 * callback = a #GAsyncReadyCallback to call 1605 * when the request is satisfied 1606 * userData = the data to pass to callback function 1607 * 1608 * Since: 2.38 1609 */ 1610 public void makeDirectoryAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1611 { 1612 g_file_make_directory_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1613 } 1614 1615 /** 1616 * Finishes an asynchronous directory creation, started with 1617 * g_file_make_directory_async(). 1618 * 1619 * Params: 1620 * result = a #GAsyncResult 1621 * 1622 * Return: %TRUE on successful directory creation, %FALSE otherwise. 1623 * 1624 * Since: 2.38 1625 * 1626 * Throws: GException on failure. 1627 */ 1628 public bool makeDirectoryFinish(AsyncResultIF result) 1629 { 1630 GError* err = null; 1631 1632 auto p = g_file_make_directory_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 1633 1634 if (err !is null) 1635 { 1636 throw new GException( new ErrorG(err) ); 1637 } 1638 1639 return p; 1640 } 1641 1642 /** 1643 * Creates a directory and any parent directories that may not 1644 * exist similar to 'mkdir -p'. If the file system does not support 1645 * creating directories, this function will fail, setting @error to 1646 * %G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists, 1647 * this function will fail setting @error to %G_IO_ERROR_EXISTS, unlike 1648 * the similar g_mkdir_with_parents(). 1649 * 1650 * For a local #GFile the newly created directories will have the default 1651 * (current) ownership and permissions of the current process. 1652 * 1653 * If @cancellable is not %NULL, then the operation can be cancelled by 1654 * triggering the cancellable object from another thread. If the operation 1655 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1656 * 1657 * Params: 1658 * cancellable = optional #GCancellable object, 1659 * %NULL to ignore 1660 * 1661 * Return: %TRUE if all directories have been successfully created, %FALSE 1662 * otherwise. 1663 * 1664 * Since: 2.18 1665 * 1666 * Throws: GException on failure. 1667 */ 1668 public bool makeDirectoryWithParents(Cancellable cancellable) 1669 { 1670 GError* err = null; 1671 1672 auto p = g_file_make_directory_with_parents(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1673 1674 if (err !is null) 1675 { 1676 throw new GException( new ErrorG(err) ); 1677 } 1678 1679 return p; 1680 } 1681 1682 /** 1683 * Creates a symbolic link named @file which contains the string 1684 * @symlink_value. 1685 * 1686 * If @cancellable is not %NULL, then the operation can be cancelled by 1687 * triggering the cancellable object from another thread. If the operation 1688 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1689 * 1690 * Params: 1691 * symlinkValue = a string with the path for the target of the new symlink 1692 * cancellable = optional #GCancellable object, 1693 * %NULL to ignore 1694 * 1695 * Return: %TRUE on the creation of a new symlink, %FALSE otherwise. 1696 * 1697 * Throws: GException on failure. 1698 */ 1699 public bool makeSymbolicLink(string symlinkValue, Cancellable cancellable) 1700 { 1701 GError* err = null; 1702 1703 auto p = g_file_make_symbolic_link(getFileStruct(), Str.toStringz(symlinkValue), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 1704 1705 if (err !is null) 1706 { 1707 throw new GException( new ErrorG(err) ); 1708 } 1709 1710 return p; 1711 } 1712 1713 /** 1714 * Recursively measures the disk usage of @file. 1715 * 1716 * This is essentially an analog of the 'du' command, but it also 1717 * reports the number of directories and non-directory files encountered 1718 * (including things like symbolic links). 1719 * 1720 * By default, errors are only reported against the toplevel file 1721 * itself. Errors found while recursing are silently ignored, unless 1722 * %G_FILE_DISK_USAGE_REPORT_ALL_ERRORS is given in @flags. 1723 * 1724 * The returned size, @disk_usage, is in bytes and should be formatted 1725 * with g_format_size() in order to get something reasonable for showing 1726 * in a user interface. 1727 * 1728 * @progress_callback and @progress_data can be given to request 1729 * periodic progress updates while scanning. See the documentation for 1730 * #GFileMeasureProgressCallback for information about when and how the 1731 * callback will be invoked. 1732 * 1733 * Params: 1734 * flags = #GFileMeasureFlags 1735 * cancellable = optional #GCancellable 1736 * progressCallback = a #GFileMeasureProgressCallback 1737 * progressData = user_data for @progress_callback 1738 * diskUsage = the number of bytes of disk space used 1739 * numDirs = the number of directories encountered 1740 * numFiles = the number of non-directories encountered 1741 * 1742 * Return: %TRUE if successful, with the out parameters set. 1743 * %FALSE otherwise, with @error set. 1744 * 1745 * Since: 2.38 1746 * 1747 * Throws: GException on failure. 1748 */ 1749 public bool measureDiskUsage(GFileMeasureFlags flags, Cancellable cancellable, GFileMeasureProgressCallback progressCallback, void* progressData, out ulong diskUsage, out ulong numDirs, out ulong numFiles) 1750 { 1751 GError* err = null; 1752 1753 auto p = g_file_measure_disk_usage(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressData, &diskUsage, &numDirs, &numFiles, &err) != 0; 1754 1755 if (err !is null) 1756 { 1757 throw new GException( new ErrorG(err) ); 1758 } 1759 1760 return p; 1761 } 1762 1763 /** 1764 * Recursively measures the disk usage of @file. 1765 * 1766 * This is the asynchronous version of g_file_measure_disk_usage(). See 1767 * there for more information. 1768 * 1769 * Params: 1770 * flags = #GFileMeasureFlags 1771 * ioPriority = the [I/O priority][io-priority] of the request 1772 * cancellable = optional #GCancellable 1773 * progressCallback = a #GFileMeasureProgressCallback 1774 * progressData = user_data for @progress_callback 1775 * callback = a #GAsyncReadyCallback to call when complete 1776 * userData = the data to pass to callback function 1777 * 1778 * Since: 2.38 1779 */ 1780 public void measureDiskUsageAsync(GFileMeasureFlags flags, int ioPriority, Cancellable cancellable, GFileMeasureProgressCallback progressCallback, void* progressData, GAsyncReadyCallback callback, void* userData) 1781 { 1782 g_file_measure_disk_usage_async(getFileStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressData, callback, userData); 1783 } 1784 1785 /** 1786 * Collects the results from an earlier call to 1787 * g_file_measure_disk_usage_async(). See g_file_measure_disk_usage() for 1788 * more information. 1789 * 1790 * Params: 1791 * result = the #GAsyncResult passed to your #GAsyncReadyCallback 1792 * diskUsage = the number of bytes of disk space used 1793 * numDirs = the number of directories encountered 1794 * numFiles = the number of non-directories encountered 1795 * 1796 * Return: %TRUE if successful, with the out parameters set. 1797 * %FALSE otherwise, with @error set. 1798 * 1799 * Since: 2.38 1800 * 1801 * Throws: GException on failure. 1802 */ 1803 public bool measureDiskUsageFinish(AsyncResultIF result, out ulong diskUsage, out ulong numDirs, out ulong numFiles) 1804 { 1805 GError* err = null; 1806 1807 auto p = g_file_measure_disk_usage_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &diskUsage, &numDirs, &numFiles, &err) != 0; 1808 1809 if (err !is null) 1810 { 1811 throw new GException( new ErrorG(err) ); 1812 } 1813 1814 return p; 1815 } 1816 1817 /** 1818 * Obtains a file or directory monitor for the given file, 1819 * depending on the type of the file. 1820 * 1821 * If @cancellable is not %NULL, then the operation can be cancelled by 1822 * triggering the cancellable object from another thread. If the operation 1823 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1824 * 1825 * Params: 1826 * flags = a set of #GFileMonitorFlags 1827 * cancellable = optional #GCancellable object, 1828 * %NULL to ignore 1829 * 1830 * Return: a #GFileMonitor for the given @file, 1831 * or %NULL on error. 1832 * Free the returned object with g_object_unref(). 1833 * 1834 * Since: 2.18 1835 * 1836 * Throws: GException on failure. 1837 */ 1838 public FileMonitor monitor(GFileMonitorFlags flags, Cancellable cancellable) 1839 { 1840 GError* err = null; 1841 1842 auto p = g_file_monitor(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1843 1844 if (err !is null) 1845 { 1846 throw new GException( new ErrorG(err) ); 1847 } 1848 1849 if(p is null) 1850 { 1851 return null; 1852 } 1853 1854 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1855 } 1856 1857 /** 1858 * Obtains a directory monitor for the given file. 1859 * This may fail if directory monitoring is not supported. 1860 * 1861 * If @cancellable is not %NULL, then the operation can be cancelled by 1862 * triggering the cancellable object from another thread. If the operation 1863 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1864 * 1865 * It does not make sense for @flags to contain 1866 * %G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to 1867 * directories. It is not possible to monitor all the files in a 1868 * directory for changes made via hard links; if you want to do this then 1869 * you must register individual watches with g_file_monitor(). 1870 * 1871 * Params: 1872 * flags = a set of #GFileMonitorFlags 1873 * cancellable = optional #GCancellable object, 1874 * %NULL to ignore 1875 * 1876 * Return: a #GFileMonitor for the given @file, 1877 * or %NULL on error. 1878 * Free the returned object with g_object_unref(). 1879 * 1880 * Throws: GException on failure. 1881 */ 1882 public FileMonitor monitorDirectory(GFileMonitorFlags flags, Cancellable cancellable) 1883 { 1884 GError* err = null; 1885 1886 auto p = g_file_monitor_directory(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1887 1888 if (err !is null) 1889 { 1890 throw new GException( new ErrorG(err) ); 1891 } 1892 1893 if(p is null) 1894 { 1895 return null; 1896 } 1897 1898 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1899 } 1900 1901 /** 1902 * Obtains a file monitor for the given file. If no file notification 1903 * mechanism exists, then regular polling of the file is used. 1904 * 1905 * If @cancellable is not %NULL, then the operation can be cancelled by 1906 * triggering the cancellable object from another thread. If the operation 1907 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1908 * 1909 * If @flags contains %G_FILE_MONITOR_WATCH_HARD_LINKS then the monitor 1910 * will also attempt to report changes made to the file via another 1911 * filename (ie, a hard link). Without this flag, you can only rely on 1912 * changes made through the filename contained in @file to be 1913 * reported. Using this flag may result in an increase in resource 1914 * usage, and may not have any effect depending on the #GFileMonitor 1915 * backend and/or filesystem type. 1916 * 1917 * Params: 1918 * flags = a set of #GFileMonitorFlags 1919 * cancellable = optional #GCancellable object, 1920 * %NULL to ignore 1921 * 1922 * Return: a #GFileMonitor for the given @file, 1923 * or %NULL on error. 1924 * Free the returned object with g_object_unref(). 1925 * 1926 * Throws: GException on failure. 1927 */ 1928 public FileMonitor monitorFile(GFileMonitorFlags flags, Cancellable cancellable) 1929 { 1930 GError* err = null; 1931 1932 auto p = g_file_monitor_file(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 1933 1934 if (err !is null) 1935 { 1936 throw new GException( new ErrorG(err) ); 1937 } 1938 1939 if(p is null) 1940 { 1941 return null; 1942 } 1943 1944 return ObjectG.getDObject!(FileMonitor)(cast(GFileMonitor*) p, true); 1945 } 1946 1947 /** 1948 * Starts a @mount_operation, mounting the volume that contains 1949 * the file @location. 1950 * 1951 * When this operation has completed, @callback will be called with 1952 * @user_user data, and the operation can be finalized with 1953 * g_file_mount_enclosing_volume_finish(). 1954 * 1955 * If @cancellable is not %NULL, then the operation can be cancelled by 1956 * triggering the cancellable object from another thread. If the operation 1957 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 1958 * 1959 * Params: 1960 * flags = flags affecting the operation 1961 * mountOperation = a #GMountOperation 1962 * or %NULL to avoid user interaction 1963 * cancellable = optional #GCancellable object, 1964 * %NULL to ignore 1965 * callback = a #GAsyncReadyCallback to call 1966 * when the request is satisfied, or %NULL 1967 * userData = the data to pass to callback function 1968 */ 1969 public void mountEnclosingVolume(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 1970 { 1971 g_file_mount_enclosing_volume(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 1972 } 1973 1974 /** 1975 * Finishes a mount operation started by g_file_mount_enclosing_volume(). 1976 * 1977 * Params: 1978 * result = a #GAsyncResult 1979 * 1980 * Return: %TRUE if successful. If an error has occurred, 1981 * this function will return %FALSE and set @error 1982 * appropriately if present. 1983 * 1984 * Throws: GException on failure. 1985 */ 1986 public bool mountEnclosingVolumeFinish(AsyncResultIF result) 1987 { 1988 GError* err = null; 1989 1990 auto p = g_file_mount_enclosing_volume_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 1991 1992 if (err !is null) 1993 { 1994 throw new GException( new ErrorG(err) ); 1995 } 1996 1997 return p; 1998 } 1999 2000 /** 2001 * Mounts a file of type G_FILE_TYPE_MOUNTABLE. 2002 * Using @mount_operation, you can request callbacks when, for instance, 2003 * passwords are needed during authentication. 2004 * 2005 * If @cancellable is not %NULL, then the operation can be cancelled by 2006 * triggering the cancellable object from another thread. If the operation 2007 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2008 * 2009 * When the operation is finished, @callback will be called. 2010 * You can then call g_file_mount_mountable_finish() to get 2011 * the result of the operation. 2012 * 2013 * Params: 2014 * flags = flags affecting the operation 2015 * mountOperation = a #GMountOperation, 2016 * or %NULL to avoid user interaction 2017 * cancellable = optional #GCancellable object, 2018 * %NULL to ignore 2019 * callback = a #GAsyncReadyCallback to call 2020 * when the request is satisfied, or %NULL 2021 * userData = the data to pass to callback function 2022 */ 2023 public void mountMountable(GMountMountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2024 { 2025 g_file_mount_mountable(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2026 } 2027 2028 /** 2029 * Finishes a mount operation. See g_file_mount_mountable() for details. 2030 * 2031 * Finish an asynchronous mount operation that was started 2032 * with g_file_mount_mountable(). 2033 * 2034 * Params: 2035 * result = a #GAsyncResult 2036 * 2037 * Return: a #GFile or %NULL on error. 2038 * Free the returned object with g_object_unref(). 2039 * 2040 * Throws: GException on failure. 2041 */ 2042 public FileIF mountMountableFinish(AsyncResultIF result) 2043 { 2044 GError* err = null; 2045 2046 auto p = g_file_mount_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err); 2047 2048 if (err !is null) 2049 { 2050 throw new GException( new ErrorG(err) ); 2051 } 2052 2053 if(p is null) 2054 { 2055 return null; 2056 } 2057 2058 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 2059 } 2060 2061 /** 2062 * Tries to move the file or directory @source to the location specified 2063 * by @destination. If native move operations are supported then this is 2064 * used, otherwise a copy + delete fallback is used. The native 2065 * implementation may support moving directories (for instance on moves 2066 * inside the same filesystem), but the fallback code does not. 2067 * 2068 * If the flag #G_FILE_COPY_OVERWRITE is specified an already 2069 * existing @destination file is overwritten. 2070 * 2071 * If the flag #G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks 2072 * will be copied as symlinks, otherwise the target of the 2073 * @source symlink will be copied. 2074 * 2075 * If @cancellable is not %NULL, then the operation can be cancelled by 2076 * triggering the cancellable object from another thread. If the operation 2077 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2078 * 2079 * If @progress_callback is not %NULL, then the operation can be monitored 2080 * by setting this to a #GFileProgressCallback function. 2081 * @progress_callback_data will be passed to this function. It is 2082 * guaranteed that this callback will be called after all data has been 2083 * transferred with the total number of bytes copied during the operation. 2084 * 2085 * If the @source file does not exist, then the %G_IO_ERROR_NOT_FOUND 2086 * error is returned, independent on the status of the @destination. 2087 * 2088 * If #G_FILE_COPY_OVERWRITE is not specified and the target exists, 2089 * then the error %G_IO_ERROR_EXISTS is returned. 2090 * 2091 * If trying to overwrite a file over a directory, the %G_IO_ERROR_IS_DIRECTORY 2092 * error is returned. If trying to overwrite a directory with a directory the 2093 * %G_IO_ERROR_WOULD_MERGE error is returned. 2094 * 2095 * If the source is a directory and the target does not exist, or 2096 * #G_FILE_COPY_OVERWRITE is specified and the target is a file, then 2097 * the %G_IO_ERROR_WOULD_RECURSE error may be returned (if the native 2098 * move operation isn't available). 2099 * 2100 * Params: 2101 * destination = #GFile pointing to the destination location 2102 * flags = set of #GFileCopyFlags 2103 * cancellable = optional #GCancellable object, 2104 * %NULL to ignore 2105 * progressCallback = #GFileProgressCallback 2106 * function for updates 2107 * progressCallbackData = gpointer to user data for 2108 * the callback function 2109 * 2110 * Return: %TRUE on successful move, %FALSE otherwise. 2111 * 2112 * Throws: GException on failure. 2113 */ 2114 public bool move(FileIF destination, GFileCopyFlags flags, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData) 2115 { 2116 GError* err = null; 2117 2118 auto p = g_file_move(getFileStruct(), (destination is null) ? null : destination.getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, &err) != 0; 2119 2120 if (err !is null) 2121 { 2122 throw new GException( new ErrorG(err) ); 2123 } 2124 2125 return p; 2126 } 2127 2128 /** 2129 * Opens an existing file for reading and writing. The result is 2130 * a #GFileIOStream that can be used to read and write the contents 2131 * of the file. 2132 * 2133 * If @cancellable is not %NULL, then the operation can be cancelled 2134 * by triggering the cancellable object from another thread. If the 2135 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2136 * returned. 2137 * 2138 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will 2139 * be returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY 2140 * error will be returned. Other errors are possible too, and depend on 2141 * what kind of filesystem the file is on. Note that in many non-local 2142 * file cases read and write streams are not supported, so make sure you 2143 * really need to do read and write streaming, rather than just opening 2144 * for reading or writing. 2145 * 2146 * Params: 2147 * cancellable = a #GCancellable 2148 * 2149 * Return: #GFileIOStream or %NULL on error. 2150 * Free the returned object with g_object_unref(). 2151 * 2152 * Since: 2.22 2153 * 2154 * Throws: GException on failure. 2155 */ 2156 public FileIOStream openReadwrite(Cancellable cancellable) 2157 { 2158 GError* err = null; 2159 2160 auto p = g_file_open_readwrite(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2161 2162 if (err !is null) 2163 { 2164 throw new GException( new ErrorG(err) ); 2165 } 2166 2167 if(p is null) 2168 { 2169 return null; 2170 } 2171 2172 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 2173 } 2174 2175 /** 2176 * Asynchronously opens @file for reading and writing. 2177 * 2178 * For more details, see g_file_open_readwrite() which is 2179 * the synchronous version of this call. 2180 * 2181 * When the operation is finished, @callback will be called. 2182 * You can then call g_file_open_readwrite_finish() to get 2183 * the result of the operation. 2184 * 2185 * Params: 2186 * ioPriority = the [I/O priority][io-priority] of the request 2187 * cancellable = optional #GCancellable object, 2188 * %NULL to ignore 2189 * callback = a #GAsyncReadyCallback to call 2190 * when the request is satisfied 2191 * userData = the data to pass to callback function 2192 * 2193 * Since: 2.22 2194 */ 2195 public void openReadwriteAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2196 { 2197 g_file_open_readwrite_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2198 } 2199 2200 /** 2201 * Finishes an asynchronous file read operation started with 2202 * g_file_open_readwrite_async(). 2203 * 2204 * Params: 2205 * res = a #GAsyncResult 2206 * 2207 * Return: a #GFileIOStream or %NULL on error. 2208 * Free the returned object with g_object_unref(). 2209 * 2210 * Since: 2.22 2211 * 2212 * Throws: GException on failure. 2213 */ 2214 public FileIOStream openReadwriteFinish(AsyncResultIF res) 2215 { 2216 GError* err = null; 2217 2218 auto p = g_file_open_readwrite_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2219 2220 if (err !is null) 2221 { 2222 throw new GException( new ErrorG(err) ); 2223 } 2224 2225 if(p is null) 2226 { 2227 return null; 2228 } 2229 2230 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 2231 } 2232 2233 /** 2234 * Polls a file of type #G_FILE_TYPE_MOUNTABLE. 2235 * 2236 * If @cancellable is not %NULL, then the operation can be cancelled by 2237 * triggering the cancellable object from another thread. If the operation 2238 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2239 * 2240 * When the operation is finished, @callback will be called. 2241 * You can then call g_file_mount_mountable_finish() to get 2242 * the result of the operation. 2243 * 2244 * Params: 2245 * cancellable = optional #GCancellable object, %NULL to ignore 2246 * callback = a #GAsyncReadyCallback to call 2247 * when the request is satisfied, or %NULL 2248 * userData = the data to pass to callback function 2249 * 2250 * Since: 2.22 2251 */ 2252 public void pollMountable(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2253 { 2254 g_file_poll_mountable(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2255 } 2256 2257 /** 2258 * Finishes a poll operation. See g_file_poll_mountable() for details. 2259 * 2260 * Finish an asynchronous poll operation that was polled 2261 * with g_file_poll_mountable(). 2262 * 2263 * Params: 2264 * result = a #GAsyncResult 2265 * 2266 * Return: %TRUE if the operation finished successfully. %FALSE 2267 * otherwise. 2268 * 2269 * Since: 2.22 2270 * 2271 * Throws: GException on failure. 2272 */ 2273 public bool pollMountableFinish(AsyncResultIF result) 2274 { 2275 GError* err = null; 2276 2277 auto p = g_file_poll_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 2278 2279 if (err !is null) 2280 { 2281 throw new GException( new ErrorG(err) ); 2282 } 2283 2284 return p; 2285 } 2286 2287 /** 2288 * Returns the #GAppInfo that is registered as the default 2289 * application to handle the file specified by @file. 2290 * 2291 * If @cancellable is not %NULL, then the operation can be cancelled by 2292 * triggering the cancellable object from another thread. If the operation 2293 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2294 * 2295 * Params: 2296 * cancellable = optional #GCancellable object, %NULL to ignore 2297 * 2298 * Return: a #GAppInfo if the handle was found, 2299 * %NULL if there were errors. 2300 * When you are done with it, release it with g_object_unref() 2301 * 2302 * Throws: GException on failure. 2303 */ 2304 public AppInfoIF queryDefaultHandler(Cancellable cancellable) 2305 { 2306 GError* err = null; 2307 2308 auto p = g_file_query_default_handler(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2309 2310 if (err !is null) 2311 { 2312 throw new GException( new ErrorG(err) ); 2313 } 2314 2315 if(p is null) 2316 { 2317 return null; 2318 } 2319 2320 return ObjectG.getDObject!(AppInfo, AppInfoIF)(cast(GAppInfo*) p); 2321 } 2322 2323 /** 2324 * Utility function to check if a particular file exists. This is 2325 * implemented using g_file_query_info() and as such does blocking I/O. 2326 * 2327 * Note that in many cases it is racy to first check for file existence 2328 * and then execute something based on the outcome of that, because the 2329 * file might have been created or removed in between the operations. The 2330 * general approach to handling that is to not check, but just do the 2331 * operation and handle the errors as they come. 2332 * 2333 * As an example of race-free checking, take the case of reading a file, 2334 * and if it doesn't exist, creating it. There are two racy versions: read 2335 * it, and on error create it; and: check if it exists, if not create it. 2336 * These can both result in two processes creating the file (with perhaps 2337 * a partially written file as the result). The correct approach is to 2338 * always try to create the file with g_file_create() which will either 2339 * atomically create the file or fail with a %G_IO_ERROR_EXISTS error. 2340 * 2341 * However, in many cases an existence check is useful in a user interface, 2342 * for instance to make a menu item sensitive/insensitive, so that you don't 2343 * have to fool users that something is possible and then just show an error 2344 * dialog. If you do this, you should make sure to also handle the errors 2345 * that can happen due to races when you execute the operation. 2346 * 2347 * Params: 2348 * cancellable = optional #GCancellable object, 2349 * %NULL to ignore 2350 * 2351 * Return: %TRUE if the file exists (and can be detected without error), 2352 * %FALSE otherwise (or if cancelled). 2353 */ 2354 public bool queryExists(Cancellable cancellable) 2355 { 2356 return g_file_query_exists(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()) != 0; 2357 } 2358 2359 /** 2360 * Utility function to inspect the #GFileType of a file. This is 2361 * implemented using g_file_query_info() and as such does blocking I/O. 2362 * 2363 * The primary use case of this method is to check if a file is 2364 * a regular file, directory, or symlink. 2365 * 2366 * Params: 2367 * flags = a set of #GFileQueryInfoFlags passed to g_file_query_info() 2368 * cancellable = optional #GCancellable object, 2369 * %NULL to ignore 2370 * 2371 * Return: The #GFileType of the file and #G_FILE_TYPE_UNKNOWN 2372 * if the file does not exist 2373 * 2374 * Since: 2.18 2375 */ 2376 public GFileType queryFileType(GFileQueryInfoFlags flags, Cancellable cancellable) 2377 { 2378 return g_file_query_file_type(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct()); 2379 } 2380 2381 /** 2382 * Similar to g_file_query_info(), but obtains information 2383 * about the filesystem the @file is on, rather than the file itself. 2384 * For instance the amount of space available and the type of 2385 * the filesystem. 2386 * 2387 * The @attributes value is a string that specifies the attributes 2388 * that should be gathered. It is not an error if it's not possible 2389 * to read a particular requested attribute from a file - it just 2390 * won't be set. @attributes should be a comma-separated list of 2391 * attributes or attribute wildcards. The wildcard "*" means all 2392 * attributes, and a wildcard like "filesystem::*" means all attributes 2393 * in the filesystem namespace. The standard namespace for filesystem 2394 * attributes is "filesystem". Common attributes of interest are 2395 * #G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem 2396 * in bytes), #G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available), 2397 * and #G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem). 2398 * 2399 * If @cancellable is not %NULL, then the operation can be cancelled 2400 * by triggering the cancellable object from another thread. If the 2401 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2402 * returned. 2403 * 2404 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will 2405 * be returned. Other errors are possible too, and depend on what 2406 * kind of filesystem the file is on. 2407 * 2408 * Params: 2409 * attributes = an attribute query string 2410 * cancellable = optional #GCancellable object, 2411 * %NULL to ignore 2412 * 2413 * Return: a #GFileInfo or %NULL if there was an error. 2414 * Free the returned object with g_object_unref(). 2415 * 2416 * Throws: GException on failure. 2417 */ 2418 public FileInfo queryFilesystemInfo(string attributes, Cancellable cancellable) 2419 { 2420 GError* err = null; 2421 2422 auto p = g_file_query_filesystem_info(getFileStruct(), Str.toStringz(attributes), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2423 2424 if (err !is null) 2425 { 2426 throw new GException( new ErrorG(err) ); 2427 } 2428 2429 if(p is null) 2430 { 2431 return null; 2432 } 2433 2434 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2435 } 2436 2437 /** 2438 * Asynchronously gets the requested information about the filesystem 2439 * that the specified @file is on. The result is a #GFileInfo object 2440 * that contains key-value attributes (such as type or size for the 2441 * file). 2442 * 2443 * For more details, see g_file_query_filesystem_info() which is the 2444 * synchronous version of this call. 2445 * 2446 * When the operation is finished, @callback will be called. You can 2447 * then call g_file_query_info_finish() to get the result of the 2448 * operation. 2449 * 2450 * Params: 2451 * attributes = an attribute query string 2452 * ioPriority = the [I/O priority][io-priority] of the request 2453 * cancellable = optional #GCancellable object, 2454 * %NULL to ignore 2455 * callback = a #GAsyncReadyCallback to call 2456 * when the request is satisfied 2457 * userData = the data to pass to callback function 2458 */ 2459 public void queryFilesystemInfoAsync(string attributes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2460 { 2461 g_file_query_filesystem_info_async(getFileStruct(), Str.toStringz(attributes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2462 } 2463 2464 /** 2465 * Finishes an asynchronous filesystem info query. 2466 * See g_file_query_filesystem_info_async(). 2467 * 2468 * Params: 2469 * res = a #GAsyncResult 2470 * 2471 * Return: #GFileInfo for given @file 2472 * or %NULL on error. 2473 * Free the returned object with g_object_unref(). 2474 * 2475 * Throws: GException on failure. 2476 */ 2477 public FileInfo queryFilesystemInfoFinish(AsyncResultIF res) 2478 { 2479 GError* err = null; 2480 2481 auto p = g_file_query_filesystem_info_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2482 2483 if (err !is null) 2484 { 2485 throw new GException( new ErrorG(err) ); 2486 } 2487 2488 if(p is null) 2489 { 2490 return null; 2491 } 2492 2493 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2494 } 2495 2496 /** 2497 * Gets the requested information about specified @file. 2498 * The result is a #GFileInfo object that contains key-value 2499 * attributes (such as the type or size of the file). 2500 * 2501 * The @attributes value is a string that specifies the file 2502 * attributes that should be gathered. It is not an error if 2503 * it's not possible to read a particular requested attribute 2504 * from a file - it just won't be set. @attributes should be a 2505 * comma-separated list of attributes or attribute wildcards. 2506 * The wildcard "*" means all attributes, and a wildcard like 2507 * "standard::*" means all attributes in the standard namespace. 2508 * An example attribute query be "standard::*,owner::user". 2509 * The standard attributes are available as defines, like 2510 * #G_FILE_ATTRIBUTE_STANDARD_NAME. 2511 * 2512 * If @cancellable is not %NULL, then the operation can be cancelled 2513 * by triggering the cancellable object from another thread. If the 2514 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2515 * returned. 2516 * 2517 * For symlinks, normally the information about the target of the 2518 * symlink is returned, rather than information about the symlink 2519 * itself. However if you pass #G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS 2520 * in @flags the information about the symlink itself will be returned. 2521 * Also, for symlinks that point to non-existing files the information 2522 * about the symlink itself will be returned. 2523 * 2524 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be 2525 * returned. Other errors are possible too, and depend on what kind of 2526 * filesystem the file is on. 2527 * 2528 * Params: 2529 * attributes = an attribute query string 2530 * flags = a set of #GFileQueryInfoFlags 2531 * cancellable = optional #GCancellable object, 2532 * %NULL to ignore 2533 * 2534 * Return: a #GFileInfo for the given @file, or %NULL 2535 * on error. Free the returned object with g_object_unref(). 2536 * 2537 * Throws: GException on failure. 2538 */ 2539 public FileInfo queryInfo(string attributes, GFileQueryInfoFlags flags, Cancellable cancellable) 2540 { 2541 GError* err = null; 2542 2543 auto p = g_file_query_info(getFileStruct(), Str.toStringz(attributes), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2544 2545 if (err !is null) 2546 { 2547 throw new GException( new ErrorG(err) ); 2548 } 2549 2550 if(p is null) 2551 { 2552 return null; 2553 } 2554 2555 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2556 } 2557 2558 /** 2559 * Asynchronously gets the requested information about specified @file. 2560 * The result is a #GFileInfo object that contains key-value attributes 2561 * (such as type or size for the file). 2562 * 2563 * For more details, see g_file_query_info() which is the synchronous 2564 * version of this call. 2565 * 2566 * When the operation is finished, @callback will be called. You can 2567 * then call g_file_query_info_finish() to get the result of the operation. 2568 * 2569 * Params: 2570 * attributes = an attribute query string 2571 * flags = a set of #GFileQueryInfoFlags 2572 * ioPriority = the [I/O priority][io-priority] of the request 2573 * cancellable = optional #GCancellable object, 2574 * %NULL to ignore 2575 * callback = a #GAsyncReadyCallback to call when the 2576 * request is satisfied 2577 * userData = the data to pass to callback function 2578 */ 2579 public void queryInfoAsync(string attributes, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2580 { 2581 g_file_query_info_async(getFileStruct(), Str.toStringz(attributes), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2582 } 2583 2584 /** 2585 * Finishes an asynchronous file info query. 2586 * See g_file_query_info_async(). 2587 * 2588 * Params: 2589 * res = a #GAsyncResult 2590 * 2591 * Return: #GFileInfo for given @file 2592 * or %NULL on error. Free the returned object with 2593 * g_object_unref(). 2594 * 2595 * Throws: GException on failure. 2596 */ 2597 public FileInfo queryInfoFinish(AsyncResultIF res) 2598 { 2599 GError* err = null; 2600 2601 auto p = g_file_query_info_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2602 2603 if (err !is null) 2604 { 2605 throw new GException( new ErrorG(err) ); 2606 } 2607 2608 if(p is null) 2609 { 2610 return null; 2611 } 2612 2613 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) p, true); 2614 } 2615 2616 /** 2617 * Obtain the list of settable attributes for the file. 2618 * 2619 * Returns the type and full attribute name of all the attributes 2620 * that can be set on this file. This doesn't mean setting it will 2621 * always succeed though, you might get an access failure, or some 2622 * specific file may not support a specific attribute. 2623 * 2624 * If @cancellable is not %NULL, then the operation can be cancelled by 2625 * triggering the cancellable object from another thread. If the operation 2626 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2627 * 2628 * Params: 2629 * cancellable = optional #GCancellable object, 2630 * %NULL to ignore 2631 * 2632 * Return: a #GFileAttributeInfoList describing the settable attributes. 2633 * When you are done with it, release it with 2634 * g_file_attribute_info_list_unref() 2635 * 2636 * Throws: GException on failure. 2637 */ 2638 public FileAttributeInfoList querySettableAttributes(Cancellable cancellable) 2639 { 2640 GError* err = null; 2641 2642 auto p = g_file_query_settable_attributes(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2643 2644 if (err !is null) 2645 { 2646 throw new GException( new ErrorG(err) ); 2647 } 2648 2649 if(p is null) 2650 { 2651 return null; 2652 } 2653 2654 return ObjectG.getDObject!(FileAttributeInfoList)(cast(GFileAttributeInfoList*) p); 2655 } 2656 2657 /** 2658 * Obtain the list of attribute namespaces where new attributes 2659 * can be created by a user. An example of this is extended 2660 * attributes (in the "xattr" namespace). 2661 * 2662 * If @cancellable is not %NULL, then the operation can be cancelled by 2663 * triggering the cancellable object from another thread. If the operation 2664 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2665 * 2666 * Params: 2667 * cancellable = optional #GCancellable object, 2668 * %NULL to ignore 2669 * 2670 * Return: a #GFileAttributeInfoList describing the writable namespaces. 2671 * When you are done with it, release it with 2672 * g_file_attribute_info_list_unref() 2673 * 2674 * Throws: GException on failure. 2675 */ 2676 public FileAttributeInfoList queryWritableNamespaces(Cancellable cancellable) 2677 { 2678 GError* err = null; 2679 2680 auto p = g_file_query_writable_namespaces(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2681 2682 if (err !is null) 2683 { 2684 throw new GException( new ErrorG(err) ); 2685 } 2686 2687 if(p is null) 2688 { 2689 return null; 2690 } 2691 2692 return ObjectG.getDObject!(FileAttributeInfoList)(cast(GFileAttributeInfoList*) p); 2693 } 2694 2695 /** 2696 * Opens a file for reading. The result is a #GFileInputStream that 2697 * can be used to read the contents of the file. 2698 * 2699 * If @cancellable is not %NULL, then the operation can be cancelled by 2700 * triggering the cancellable object from another thread. If the operation 2701 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2702 * 2703 * If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be 2704 * returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY 2705 * error will be returned. Other errors are possible too, and depend 2706 * on what kind of filesystem the file is on. 2707 * 2708 * Params: 2709 * cancellable = a #GCancellable 2710 * 2711 * Return: #GFileInputStream or %NULL on error. 2712 * Free the returned object with g_object_unref(). 2713 * 2714 * Throws: GException on failure. 2715 */ 2716 public FileInputStream read(Cancellable cancellable) 2717 { 2718 GError* err = null; 2719 2720 auto p = g_file_read(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2721 2722 if (err !is null) 2723 { 2724 throw new GException( new ErrorG(err) ); 2725 } 2726 2727 if(p is null) 2728 { 2729 return null; 2730 } 2731 2732 return ObjectG.getDObject!(FileInputStream)(cast(GFileInputStream*) p, true); 2733 } 2734 2735 /** 2736 * Asynchronously opens @file for reading. 2737 * 2738 * For more details, see g_file_read() which is 2739 * the synchronous version of this call. 2740 * 2741 * When the operation is finished, @callback will be called. 2742 * You can then call g_file_read_finish() to get the result 2743 * of the operation. 2744 * 2745 * Params: 2746 * ioPriority = the [I/O priority][io-priority] of the request 2747 * cancellable = optional #GCancellable object, 2748 * %NULL to ignore 2749 * callback = a #GAsyncReadyCallback to call 2750 * when the request is satisfied 2751 * userData = the data to pass to callback function 2752 */ 2753 public void readAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2754 { 2755 g_file_read_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2756 } 2757 2758 /** 2759 * Finishes an asynchronous file read operation started with 2760 * g_file_read_async(). 2761 * 2762 * Params: 2763 * res = a #GAsyncResult 2764 * 2765 * Return: a #GFileInputStream or %NULL on error. 2766 * Free the returned object with g_object_unref(). 2767 * 2768 * Throws: GException on failure. 2769 */ 2770 public FileInputStream readFinish(AsyncResultIF res) 2771 { 2772 GError* err = null; 2773 2774 auto p = g_file_read_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 2775 2776 if (err !is null) 2777 { 2778 throw new GException( new ErrorG(err) ); 2779 } 2780 2781 if(p is null) 2782 { 2783 return null; 2784 } 2785 2786 return ObjectG.getDObject!(FileInputStream)(cast(GFileInputStream*) p, true); 2787 } 2788 2789 /** 2790 * Returns an output stream for overwriting the file, possibly 2791 * creating a backup copy of the file first. If the file doesn't exist, 2792 * it will be created. 2793 * 2794 * This will try to replace the file in the safest way possible so 2795 * that any errors during the writing will not affect an already 2796 * existing copy of the file. For instance, for local files it 2797 * may write to a temporary file and then atomically rename over 2798 * the destination when the stream is closed. 2799 * 2800 * By default files created are generally readable by everyone, 2801 * but if you pass #G_FILE_CREATE_PRIVATE in @flags the file 2802 * will be made readable only to the current user, to the level that 2803 * is supported on the target filesystem. 2804 * 2805 * If @cancellable is not %NULL, then the operation can be cancelled 2806 * by triggering the cancellable object from another thread. If the 2807 * operation was cancelled, the error %G_IO_ERROR_CANCELLED will be 2808 * returned. 2809 * 2810 * If you pass in a non-%NULL @etag value and @file already exists, then 2811 * this value is compared to the current entity tag of the file, and if 2812 * they differ an %G_IO_ERROR_WRONG_ETAG error is returned. This 2813 * generally means that the file has been changed since you last read 2814 * it. You can get the new etag from g_file_output_stream_get_etag() 2815 * after you've finished writing and closed the #GFileOutputStream. When 2816 * you load a new file you can use g_file_input_stream_query_info() to 2817 * get the etag of the file. 2818 * 2819 * If @make_backup is %TRUE, this function will attempt to make a 2820 * backup of the current file before overwriting it. If this fails 2821 * a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you 2822 * want to replace anyway, try again with @make_backup set to %FALSE. 2823 * 2824 * If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will 2825 * be returned, and if the file is some other form of non-regular file 2826 * then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some 2827 * file systems don't allow all file names, and may return an 2828 * %G_IO_ERROR_INVALID_FILENAME error, and if the name is to long 2829 * %G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are 2830 * possible too, and depend on what kind of filesystem the file is on. 2831 * 2832 * Params: 2833 * etag = an optional [entity tag][gfile-etag] 2834 * for the current #GFile, or #NULL to ignore 2835 * makeBackup = %TRUE if a backup should be created 2836 * flags = a set of #GFileCreateFlags 2837 * cancellable = optional #GCancellable object, 2838 * %NULL to ignore 2839 * 2840 * Return: a #GFileOutputStream or %NULL on error. 2841 * Free the returned object with g_object_unref(). 2842 * 2843 * Throws: GException on failure. 2844 */ 2845 public FileOutputStream replace(string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable) 2846 { 2847 GError* err = null; 2848 2849 auto p = g_file_replace(getFileStruct(), Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 2850 2851 if (err !is null) 2852 { 2853 throw new GException( new ErrorG(err) ); 2854 } 2855 2856 if(p is null) 2857 { 2858 return null; 2859 } 2860 2861 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 2862 } 2863 2864 /** 2865 * Asynchronously overwrites the file, replacing the contents, 2866 * possibly creating a backup copy of the file first. 2867 * 2868 * For more details, see g_file_replace() which is 2869 * the synchronous version of this call. 2870 * 2871 * When the operation is finished, @callback will be called. 2872 * You can then call g_file_replace_finish() to get the result 2873 * of the operation. 2874 * 2875 * Params: 2876 * etag = an [entity tag][gfile-etag] for the current #GFile, 2877 * or %NULL to ignore 2878 * makeBackup = %TRUE if a backup should be created 2879 * flags = a set of #GFileCreateFlags 2880 * ioPriority = the [I/O priority][io-priority] of the request 2881 * cancellable = optional #GCancellable object, 2882 * %NULL to ignore 2883 * callback = a #GAsyncReadyCallback to call 2884 * when the request is satisfied 2885 * userData = the data to pass to callback function 2886 */ 2887 public void replaceAsync(string etag, bool makeBackup, GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2888 { 2889 g_file_replace_async(getFileStruct(), Str.toStringz(etag), makeBackup, flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 2890 } 2891 2892 /** 2893 * Replaces the contents of @file with @contents of @length bytes. 2894 * 2895 * If @etag is specified (not %NULL), any existing file must have that etag, 2896 * or the error %G_IO_ERROR_WRONG_ETAG will be returned. 2897 * 2898 * If @make_backup is %TRUE, this function will attempt to make a backup 2899 * of @file. Internally, it uses g_file_replace(), so will try to replace the 2900 * file contents in the safest way possible. For example, atomic renames are 2901 * used when replacing local files’ contents. 2902 * 2903 * If @cancellable is not %NULL, then the operation can be cancelled by 2904 * triggering the cancellable object from another thread. If the operation 2905 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2906 * 2907 * The returned @new_etag can be used to verify that the file hasn't 2908 * changed the next time it is saved over. 2909 * 2910 * Params: 2911 * contents = a string containing the new contents for @file 2912 * length = the length of @contents in bytes 2913 * etag = the old [entity-tag][gfile-etag] for the document, 2914 * or %NULL 2915 * makeBackup = %TRUE if a backup should be created 2916 * flags = a set of #GFileCreateFlags 2917 * newEtag = a location to a new [entity tag][gfile-etag] 2918 * for the document. This should be freed with g_free() when no longer 2919 * needed, or %NULL 2920 * cancellable = optional #GCancellable object, %NULL to ignore 2921 * 2922 * Return: %TRUE if successful. If an error has occurred, this function 2923 * will return %FALSE and set @error appropriately if present. 2924 * 2925 * Throws: GException on failure. 2926 */ 2927 public bool replaceContents(string contents, string etag, bool makeBackup, GFileCreateFlags flags, out string newEtag, Cancellable cancellable) 2928 { 2929 char* outnewEtag = null; 2930 GError* err = null; 2931 2932 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; 2933 2934 if (err !is null) 2935 { 2936 throw new GException( new ErrorG(err) ); 2937 } 2938 2939 newEtag = Str.toString(outnewEtag); 2940 2941 return p; 2942 } 2943 2944 /** 2945 * Starts an asynchronous replacement of @file with the given 2946 * @contents of @length bytes. @etag will replace the document's 2947 * current entity tag. 2948 * 2949 * When this operation has completed, @callback will be called with 2950 * @user_user data, and the operation can be finalized with 2951 * g_file_replace_contents_finish(). 2952 * 2953 * If @cancellable is not %NULL, then the operation can be cancelled by 2954 * triggering the cancellable object from another thread. If the operation 2955 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 2956 * 2957 * If @make_backup is %TRUE, this function will attempt to 2958 * make a backup of @file. 2959 * 2960 * Note that no copy of @content will be made, so it must stay valid 2961 * until @callback is called. See g_file_replace_contents_bytes_async() 2962 * for a #GBytes version that will automatically hold a reference to the 2963 * contents (without copying) for the duration of the call. 2964 * 2965 * Params: 2966 * contents = string of contents to replace the file with 2967 * length = the length of @contents in bytes 2968 * etag = a new [entity tag][gfile-etag] for the @file, or %NULL 2969 * makeBackup = %TRUE if a backup should be created 2970 * flags = a set of #GFileCreateFlags 2971 * cancellable = optional #GCancellable object, %NULL to ignore 2972 * callback = a #GAsyncReadyCallback to call when the request is satisfied 2973 * userData = the data to pass to callback function 2974 */ 2975 public void replaceContentsAsync(string contents, string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 2976 { 2977 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); 2978 } 2979 2980 /** 2981 * Same as g_file_replace_contents_async() but takes a #GBytes input instead. 2982 * This function will keep a ref on @contents until the operation is done. 2983 * Unlike g_file_replace_contents_async() this allows forgetting about the 2984 * content without waiting for the callback. 2985 * 2986 * When this operation has completed, @callback will be called with 2987 * @user_user data, and the operation can be finalized with 2988 * g_file_replace_contents_finish(). 2989 * 2990 * Params: 2991 * contents = a #GBytes 2992 * etag = a new [entity tag][gfile-etag] for the @file, or %NULL 2993 * makeBackup = %TRUE if a backup should be created 2994 * flags = a set of #GFileCreateFlags 2995 * cancellable = optional #GCancellable object, %NULL to ignore 2996 * callback = a #GAsyncReadyCallback to call when the request is satisfied 2997 * userData = the data to pass to callback function 2998 * 2999 * Since: 2.40 3000 */ 3001 public void replaceContentsBytesAsync(Bytes contents, string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3002 { 3003 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); 3004 } 3005 3006 /** 3007 * Finishes an asynchronous replace of the given @file. See 3008 * g_file_replace_contents_async(). Sets @new_etag to the new entity 3009 * tag for the document, if present. 3010 * 3011 * Params: 3012 * res = a #GAsyncResult 3013 * newEtag = a location of a new [entity tag][gfile-etag] 3014 * for the document. This should be freed with g_free() when it is no 3015 * longer needed, or %NULL 3016 * 3017 * Return: %TRUE on success, %FALSE on failure. 3018 * 3019 * Throws: GException on failure. 3020 */ 3021 public bool replaceContentsFinish(AsyncResultIF res, out string newEtag) 3022 { 3023 char* outnewEtag = null; 3024 GError* err = null; 3025 3026 auto p = g_file_replace_contents_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &outnewEtag, &err) != 0; 3027 3028 if (err !is null) 3029 { 3030 throw new GException( new ErrorG(err) ); 3031 } 3032 3033 newEtag = Str.toString(outnewEtag); 3034 3035 return p; 3036 } 3037 3038 /** 3039 * Finishes an asynchronous file replace operation started with 3040 * g_file_replace_async(). 3041 * 3042 * Params: 3043 * res = a #GAsyncResult 3044 * 3045 * Return: a #GFileOutputStream, or %NULL on error. 3046 * Free the returned object with g_object_unref(). 3047 * 3048 * Throws: GException on failure. 3049 */ 3050 public FileOutputStream replaceFinish(AsyncResultIF res) 3051 { 3052 GError* err = null; 3053 3054 auto p = g_file_replace_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3055 3056 if (err !is null) 3057 { 3058 throw new GException( new ErrorG(err) ); 3059 } 3060 3061 if(p is null) 3062 { 3063 return null; 3064 } 3065 3066 return ObjectG.getDObject!(FileOutputStream)(cast(GFileOutputStream*) p, true); 3067 } 3068 3069 /** 3070 * Returns an output stream for overwriting the file in readwrite mode, 3071 * possibly creating a backup copy of the file first. If the file doesn't 3072 * exist, it will be created. 3073 * 3074 * For details about the behaviour, see g_file_replace() which does the 3075 * same thing but returns an output stream only. 3076 * 3077 * Note that in many non-local file cases read and write streams are not 3078 * supported, so make sure you really need to do read and write streaming, 3079 * rather than just opening for reading or writing. 3080 * 3081 * Params: 3082 * etag = an optional [entity tag][gfile-etag] 3083 * for the current #GFile, or #NULL to ignore 3084 * makeBackup = %TRUE if a backup should be created 3085 * flags = a set of #GFileCreateFlags 3086 * cancellable = optional #GCancellable object, 3087 * %NULL to ignore 3088 * 3089 * Return: a #GFileIOStream or %NULL on error. 3090 * Free the returned object with g_object_unref(). 3091 * 3092 * Since: 2.22 3093 * 3094 * Throws: GException on failure. 3095 */ 3096 public FileIOStream replaceReadwrite(string etag, bool makeBackup, GFileCreateFlags flags, Cancellable cancellable) 3097 { 3098 GError* err = null; 3099 3100 auto p = g_file_replace_readwrite(getFileStruct(), Str.toStringz(etag), makeBackup, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 3101 3102 if (err !is null) 3103 { 3104 throw new GException( new ErrorG(err) ); 3105 } 3106 3107 if(p is null) 3108 { 3109 return null; 3110 } 3111 3112 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 3113 } 3114 3115 /** 3116 * Asynchronously overwrites the file in read-write mode, 3117 * replacing the contents, possibly creating a backup copy 3118 * of the file first. 3119 * 3120 * For more details, see g_file_replace_readwrite() which is 3121 * the synchronous version of this call. 3122 * 3123 * When the operation is finished, @callback will be called. 3124 * You can then call g_file_replace_readwrite_finish() to get 3125 * the result of the operation. 3126 * 3127 * Params: 3128 * etag = an [entity tag][gfile-etag] for the current #GFile, 3129 * or %NULL to ignore 3130 * makeBackup = %TRUE if a backup should be created 3131 * flags = a set of #GFileCreateFlags 3132 * ioPriority = the [I/O priority][io-priority] of the request 3133 * cancellable = optional #GCancellable object, 3134 * %NULL to ignore 3135 * callback = a #GAsyncReadyCallback to call 3136 * when the request is satisfied 3137 * userData = the data to pass to callback function 3138 * 3139 * Since: 2.22 3140 */ 3141 public void replaceReadwriteAsync(string etag, bool makeBackup, GFileCreateFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3142 { 3143 g_file_replace_readwrite_async(getFileStruct(), Str.toStringz(etag), makeBackup, flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3144 } 3145 3146 /** 3147 * Finishes an asynchronous file replace operation started with 3148 * g_file_replace_readwrite_async(). 3149 * 3150 * Params: 3151 * res = a #GAsyncResult 3152 * 3153 * Return: a #GFileIOStream, or %NULL on error. 3154 * Free the returned object with g_object_unref(). 3155 * 3156 * Since: 2.22 3157 * 3158 * Throws: GException on failure. 3159 */ 3160 public FileIOStream replaceReadwriteFinish(AsyncResultIF res) 3161 { 3162 GError* err = null; 3163 3164 auto p = g_file_replace_readwrite_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3165 3166 if (err !is null) 3167 { 3168 throw new GException( new ErrorG(err) ); 3169 } 3170 3171 if(p is null) 3172 { 3173 return null; 3174 } 3175 3176 return ObjectG.getDObject!(FileIOStream)(cast(GFileIOStream*) p, true); 3177 } 3178 3179 /** 3180 * Resolves a relative path for @file to an absolute path. 3181 * 3182 * This call does no blocking I/O. 3183 * 3184 * Params: 3185 * relativePath = a given relative path string 3186 * 3187 * Return: #GFile to the resolved path. 3188 * %NULL if @relative_path is %NULL or if @file is invalid. 3189 * Free the returned object with g_object_unref(). 3190 */ 3191 public FileIF resolveRelativePath(string relativePath) 3192 { 3193 auto p = g_file_resolve_relative_path(getFileStruct(), Str.toStringz(relativePath)); 3194 3195 if(p is null) 3196 { 3197 return null; 3198 } 3199 3200 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3201 } 3202 3203 /** 3204 * Sets an attribute in the file with attribute name @attribute to @value. 3205 * 3206 * Some attributes can be unset by setting @attribute to 3207 * %G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL. 3208 * 3209 * If @cancellable is not %NULL, then the operation can be cancelled by 3210 * triggering the cancellable object from another thread. If the operation 3211 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3212 * 3213 * Params: 3214 * attribute = a string containing the attribute's name 3215 * type = The type of the attribute 3216 * valueP = a pointer to the value (or the pointer 3217 * itself if the type is a pointer type) 3218 * flags = a set of #GFileQueryInfoFlags 3219 * cancellable = optional #GCancellable object, 3220 * %NULL to ignore 3221 * 3222 * Return: %TRUE if the attribute was set, %FALSE otherwise. 3223 * 3224 * Throws: GException on failure. 3225 */ 3226 public bool setAttribute(string attribute, GFileAttributeType type, void* valueP, GFileQueryInfoFlags flags, Cancellable cancellable) 3227 { 3228 GError* err = null; 3229 3230 auto p = g_file_set_attribute(getFileStruct(), Str.toStringz(attribute), type, valueP, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3231 3232 if (err !is null) 3233 { 3234 throw new GException( new ErrorG(err) ); 3235 } 3236 3237 return p; 3238 } 3239 3240 /** 3241 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value. 3242 * If @attribute is of a different type, this operation will fail, 3243 * returning %FALSE. 3244 * 3245 * If @cancellable is not %NULL, then the operation can be cancelled by 3246 * triggering the cancellable object from another thread. If the operation 3247 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3248 * 3249 * Params: 3250 * attribute = a string containing the attribute's name 3251 * value = a string containing the attribute's new value 3252 * flags = a #GFileQueryInfoFlags 3253 * cancellable = optional #GCancellable object, 3254 * %NULL to ignore 3255 * 3256 * Return: %TRUE if the @attribute was successfully set to @value 3257 * in the @file, %FALSE otherwise. 3258 * 3259 * Throws: GException on failure. 3260 */ 3261 public bool setAttributeByteString(string attribute, string value, GFileQueryInfoFlags flags, Cancellable cancellable) 3262 { 3263 GError* err = null; 3264 3265 auto p = g_file_set_attribute_byte_string(getFileStruct(), Str.toStringz(attribute), Str.toStringz(value), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3266 3267 if (err !is null) 3268 { 3269 throw new GException( new ErrorG(err) ); 3270 } 3271 3272 return p; 3273 } 3274 3275 /** 3276 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value. 3277 * If @attribute is of a different type, this operation will fail. 3278 * 3279 * If @cancellable is not %NULL, then the operation can be cancelled by 3280 * triggering the cancellable object from another thread. If the operation 3281 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3282 * 3283 * Params: 3284 * attribute = a string containing the attribute's name 3285 * value = a #gint32 containing the attribute's new value 3286 * flags = a #GFileQueryInfoFlags 3287 * cancellable = optional #GCancellable object, 3288 * %NULL to ignore 3289 * 3290 * Return: %TRUE if the @attribute was successfully set to @value 3291 * in the @file, %FALSE otherwise. 3292 * 3293 * Throws: GException on failure. 3294 */ 3295 public bool setAttributeInt32(string attribute, int value, GFileQueryInfoFlags flags, Cancellable cancellable) 3296 { 3297 GError* err = null; 3298 3299 auto p = g_file_set_attribute_int32(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3300 3301 if (err !is null) 3302 { 3303 throw new GException( new ErrorG(err) ); 3304 } 3305 3306 return p; 3307 } 3308 3309 /** 3310 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value. 3311 * If @attribute is of a different type, this operation will fail. 3312 * 3313 * If @cancellable is not %NULL, then the operation can be cancelled by 3314 * triggering the cancellable object from another thread. If the operation 3315 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3316 * 3317 * Params: 3318 * attribute = a string containing the attribute's name 3319 * value = a #guint64 containing the attribute's new value 3320 * flags = a #GFileQueryInfoFlags 3321 * cancellable = optional #GCancellable object, 3322 * %NULL to ignore 3323 * 3324 * Return: %TRUE if the @attribute was successfully set, %FALSE otherwise. 3325 * 3326 * Throws: GException on failure. 3327 */ 3328 public bool setAttributeInt64(string attribute, long value, GFileQueryInfoFlags flags, Cancellable cancellable) 3329 { 3330 GError* err = null; 3331 3332 auto p = g_file_set_attribute_int64(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3333 3334 if (err !is null) 3335 { 3336 throw new GException( new ErrorG(err) ); 3337 } 3338 3339 return p; 3340 } 3341 3342 /** 3343 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value. 3344 * If @attribute is of a different type, this operation will fail. 3345 * 3346 * If @cancellable is not %NULL, then the operation can be cancelled by 3347 * triggering the cancellable object from another thread. If the operation 3348 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3349 * 3350 * Params: 3351 * attribute = a string containing the attribute's name 3352 * value = a string containing the attribute's value 3353 * flags = #GFileQueryInfoFlags 3354 * cancellable = optional #GCancellable object, 3355 * %NULL to ignore 3356 * 3357 * Return: %TRUE if the @attribute was successfully set, %FALSE otherwise. 3358 * 3359 * Throws: GException on failure. 3360 */ 3361 public bool setAttributeString(string attribute, string value, GFileQueryInfoFlags flags, Cancellable cancellable) 3362 { 3363 GError* err = null; 3364 3365 auto p = g_file_set_attribute_string(getFileStruct(), Str.toStringz(attribute), Str.toStringz(value), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3366 3367 if (err !is null) 3368 { 3369 throw new GException( new ErrorG(err) ); 3370 } 3371 3372 return p; 3373 } 3374 3375 /** 3376 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value. 3377 * If @attribute is of a different type, this operation will fail. 3378 * 3379 * If @cancellable is not %NULL, then the operation can be cancelled by 3380 * triggering the cancellable object from another thread. If the operation 3381 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3382 * 3383 * Params: 3384 * attribute = a string containing the attribute's name 3385 * value = a #guint32 containing the attribute's new value 3386 * flags = a #GFileQueryInfoFlags 3387 * cancellable = optional #GCancellable object, 3388 * %NULL to ignore 3389 * 3390 * Return: %TRUE if the @attribute was successfully set to @value 3391 * in the @file, %FALSE otherwise. 3392 * 3393 * Throws: GException on failure. 3394 */ 3395 public bool setAttributeUint32(string attribute, uint value, GFileQueryInfoFlags flags, Cancellable cancellable) 3396 { 3397 GError* err = null; 3398 3399 auto p = g_file_set_attribute_uint32(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3400 3401 if (err !is null) 3402 { 3403 throw new GException( new ErrorG(err) ); 3404 } 3405 3406 return p; 3407 } 3408 3409 /** 3410 * Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value. 3411 * If @attribute is of a different type, this operation will fail. 3412 * 3413 * If @cancellable is not %NULL, then the operation can be cancelled by 3414 * triggering the cancellable object from another thread. If the operation 3415 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3416 * 3417 * Params: 3418 * attribute = a string containing the attribute's name 3419 * value = a #guint64 containing the attribute's new value 3420 * flags = a #GFileQueryInfoFlags 3421 * cancellable = optional #GCancellable object, 3422 * %NULL to ignore 3423 * 3424 * Return: %TRUE if the @attribute was successfully set to @value 3425 * in the @file, %FALSE otherwise. 3426 * 3427 * Throws: GException on failure. 3428 */ 3429 public bool setAttributeUint64(string attribute, ulong value, GFileQueryInfoFlags flags, Cancellable cancellable) 3430 { 3431 GError* err = null; 3432 3433 auto p = g_file_set_attribute_uint64(getFileStruct(), Str.toStringz(attribute), value, flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3434 3435 if (err !is null) 3436 { 3437 throw new GException( new ErrorG(err) ); 3438 } 3439 3440 return p; 3441 } 3442 3443 /** 3444 * Asynchronously sets the attributes of @file with @info. 3445 * 3446 * For more details, see g_file_set_attributes_from_info(), 3447 * which is the synchronous version of this call. 3448 * 3449 * When the operation is finished, @callback will be called. 3450 * You can then call g_file_set_attributes_finish() to get 3451 * the result of the operation. 3452 * 3453 * Params: 3454 * info = a #GFileInfo 3455 * flags = a #GFileQueryInfoFlags 3456 * ioPriority = the [I/O priority][io-priority] of the request 3457 * cancellable = optional #GCancellable object, 3458 * %NULL to ignore 3459 * callback = a #GAsyncReadyCallback 3460 * userData = a #gpointer 3461 */ 3462 public void setAttributesAsync(FileInfo info, GFileQueryInfoFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3463 { 3464 g_file_set_attributes_async(getFileStruct(), (info is null) ? null : info.getFileInfoStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3465 } 3466 3467 /** 3468 * Finishes setting an attribute started in g_file_set_attributes_async(). 3469 * 3470 * Params: 3471 * result = a #GAsyncResult 3472 * info = a #GFileInfo 3473 * 3474 * Return: %TRUE if the attributes were set correctly, %FALSE otherwise. 3475 * 3476 * Throws: GException on failure. 3477 */ 3478 public bool setAttributesFinish(AsyncResultIF result, out FileInfo info) 3479 { 3480 GFileInfo* outinfo = null; 3481 GError* err = null; 3482 3483 auto p = g_file_set_attributes_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &outinfo, &err) != 0; 3484 3485 if (err !is null) 3486 { 3487 throw new GException( new ErrorG(err) ); 3488 } 3489 3490 info = ObjectG.getDObject!(FileInfo)(outinfo); 3491 3492 return p; 3493 } 3494 3495 /** 3496 * Tries to set all attributes in the #GFileInfo on the target 3497 * values, not stopping on the first error. 3498 * 3499 * If there is any error during this operation then @error will 3500 * be set to the first error. Error on particular fields are flagged 3501 * by setting the "status" field in the attribute value to 3502 * %G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can 3503 * also detect further errors. 3504 * 3505 * If @cancellable is not %NULL, then the operation can be cancelled by 3506 * triggering the cancellable object from another thread. If the operation 3507 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3508 * 3509 * Params: 3510 * info = a #GFileInfo 3511 * flags = #GFileQueryInfoFlags 3512 * cancellable = optional #GCancellable object, 3513 * %NULL to ignore 3514 * 3515 * Return: %FALSE if there was any error, %TRUE otherwise. 3516 * 3517 * Throws: GException on failure. 3518 */ 3519 public bool setAttributesFromInfo(FileInfo info, GFileQueryInfoFlags flags, Cancellable cancellable) 3520 { 3521 GError* err = null; 3522 3523 auto p = g_file_set_attributes_from_info(getFileStruct(), (info is null) ? null : info.getFileInfoStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3524 3525 if (err !is null) 3526 { 3527 throw new GException( new ErrorG(err) ); 3528 } 3529 3530 return p; 3531 } 3532 3533 /** 3534 * Renames @file to the specified display name. 3535 * 3536 * The display name is converted from UTF-8 to the correct encoding 3537 * for the target filesystem if possible and the @file is renamed to this. 3538 * 3539 * If you want to implement a rename operation in the user interface the 3540 * edit name (#G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the 3541 * initial value in the rename widget, and then the result after editing 3542 * should be passed to g_file_set_display_name(). 3543 * 3544 * On success the resulting converted filename is returned. 3545 * 3546 * If @cancellable is not %NULL, then the operation can be cancelled by 3547 * triggering the cancellable object from another thread. If the operation 3548 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3549 * 3550 * Params: 3551 * displayName = a string 3552 * cancellable = optional #GCancellable object, 3553 * %NULL to ignore 3554 * 3555 * Return: a #GFile specifying what @file was renamed to, 3556 * or %NULL if there was an error. 3557 * Free the returned object with g_object_unref(). 3558 * 3559 * Throws: GException on failure. 3560 */ 3561 public FileIF setDisplayName(string displayName, Cancellable cancellable) 3562 { 3563 GError* err = null; 3564 3565 auto p = g_file_set_display_name(getFileStruct(), Str.toStringz(displayName), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 3566 3567 if (err !is null) 3568 { 3569 throw new GException( new ErrorG(err) ); 3570 } 3571 3572 if(p is null) 3573 { 3574 return null; 3575 } 3576 3577 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3578 } 3579 3580 /** 3581 * Asynchronously sets the display name for a given #GFile. 3582 * 3583 * For more details, see g_file_set_display_name() which is 3584 * the synchronous version of this call. 3585 * 3586 * When the operation is finished, @callback will be called. 3587 * You can then call g_file_set_display_name_finish() to get 3588 * the result of the operation. 3589 * 3590 * Params: 3591 * displayName = a string 3592 * ioPriority = the [I/O priority][io-priority] of the request 3593 * cancellable = optional #GCancellable object, 3594 * %NULL to ignore 3595 * callback = a #GAsyncReadyCallback to call 3596 * when the request is satisfied 3597 * userData = the data to pass to callback function 3598 */ 3599 public void setDisplayNameAsync(string displayName, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3600 { 3601 g_file_set_display_name_async(getFileStruct(), Str.toStringz(displayName), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3602 } 3603 3604 /** 3605 * Finishes setting a display name started with 3606 * g_file_set_display_name_async(). 3607 * 3608 * Params: 3609 * res = a #GAsyncResult 3610 * 3611 * Return: a #GFile or %NULL on error. 3612 * Free the returned object with g_object_unref(). 3613 * 3614 * Throws: GException on failure. 3615 */ 3616 public FileIF setDisplayNameFinish(AsyncResultIF res) 3617 { 3618 GError* err = null; 3619 3620 auto p = g_file_set_display_name_finish(getFileStruct(), (res is null) ? null : res.getAsyncResultStruct(), &err); 3621 3622 if (err !is null) 3623 { 3624 throw new GException( new ErrorG(err) ); 3625 } 3626 3627 if(p is null) 3628 { 3629 return null; 3630 } 3631 3632 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 3633 } 3634 3635 /** 3636 * Starts a file of type #G_FILE_TYPE_MOUNTABLE. 3637 * Using @start_operation, you can request callbacks when, for instance, 3638 * passwords are needed during authentication. 3639 * 3640 * If @cancellable is not %NULL, then the operation can be cancelled by 3641 * triggering the cancellable object from another thread. If the operation 3642 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3643 * 3644 * When the operation is finished, @callback will be called. 3645 * You can then call g_file_mount_mountable_finish() to get 3646 * the result of the operation. 3647 * 3648 * Params: 3649 * flags = flags affecting the operation 3650 * startOperation = a #GMountOperation, or %NULL to avoid user interaction 3651 * cancellable = optional #GCancellable object, %NULL to ignore 3652 * callback = a #GAsyncReadyCallback to call when the request is satisfied, or %NULL 3653 * userData = the data to pass to callback function 3654 * 3655 * Since: 2.22 3656 */ 3657 public void startMountable(GDriveStartFlags flags, MountOperation startOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3658 { 3659 g_file_start_mountable(getFileStruct(), flags, (startOperation is null) ? null : startOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3660 } 3661 3662 /** 3663 * Finishes a start operation. See g_file_start_mountable() for details. 3664 * 3665 * Finish an asynchronous start operation that was started 3666 * with g_file_start_mountable(). 3667 * 3668 * Params: 3669 * result = a #GAsyncResult 3670 * 3671 * Return: %TRUE if the operation finished successfully. %FALSE 3672 * otherwise. 3673 * 3674 * Since: 2.22 3675 * 3676 * Throws: GException on failure. 3677 */ 3678 public bool startMountableFinish(AsyncResultIF result) 3679 { 3680 GError* err = null; 3681 3682 auto p = g_file_start_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3683 3684 if (err !is null) 3685 { 3686 throw new GException( new ErrorG(err) ); 3687 } 3688 3689 return p; 3690 } 3691 3692 /** 3693 * Stops a file of type #G_FILE_TYPE_MOUNTABLE. 3694 * 3695 * If @cancellable is not %NULL, then the operation can be cancelled by 3696 * triggering the cancellable object from another thread. If the operation 3697 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3698 * 3699 * When the operation is finished, @callback will be called. 3700 * You can then call g_file_stop_mountable_finish() to get 3701 * the result of the operation. 3702 * 3703 * Params: 3704 * flags = flags affecting the operation 3705 * mountOperation = a #GMountOperation, 3706 * or %NULL to avoid user interaction. 3707 * cancellable = optional #GCancellable object, 3708 * %NULL to ignore 3709 * callback = a #GAsyncReadyCallback to call 3710 * when the request is satisfied, or %NULL 3711 * userData = the data to pass to callback function 3712 * 3713 * Since: 2.22 3714 */ 3715 public void stopMountable(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3716 { 3717 g_file_stop_mountable(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3718 } 3719 3720 /** 3721 * Finishes an stop operation, see g_file_stop_mountable() for details. 3722 * 3723 * Finish an asynchronous stop operation that was started 3724 * with g_file_stop_mountable(). 3725 * 3726 * Params: 3727 * result = a #GAsyncResult 3728 * 3729 * Return: %TRUE if the operation finished successfully. 3730 * %FALSE otherwise. 3731 * 3732 * Since: 2.22 3733 * 3734 * Throws: GException on failure. 3735 */ 3736 public bool stopMountableFinish(AsyncResultIF result) 3737 { 3738 GError* err = null; 3739 3740 auto p = g_file_stop_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3741 3742 if (err !is null) 3743 { 3744 throw new GException( new ErrorG(err) ); 3745 } 3746 3747 return p; 3748 } 3749 3750 /** 3751 * Checks if @file supports 3752 * [thread-default contexts][g-main-context-push-thread-default-context]. 3753 * If this returns %FALSE, you cannot perform asynchronous operations on 3754 * @file in a thread that has a thread-default context. 3755 * 3756 * Return: Whether or not @file supports thread-default contexts. 3757 * 3758 * Since: 2.22 3759 */ 3760 public bool supportsThreadContexts() 3761 { 3762 return g_file_supports_thread_contexts(getFileStruct()) != 0; 3763 } 3764 3765 /** 3766 * Sends @file to the "Trashcan", if possible. This is similar to 3767 * deleting it, but the user can recover it before emptying the trashcan. 3768 * Not all file systems support trashing, so this call can return the 3769 * %G_IO_ERROR_NOT_SUPPORTED error. 3770 * 3771 * If @cancellable is not %NULL, then the operation can be cancelled by 3772 * triggering the cancellable object from another thread. If the operation 3773 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3774 * 3775 * Params: 3776 * cancellable = optional #GCancellable object, 3777 * %NULL to ignore 3778 * 3779 * Return: %TRUE on successful trash, %FALSE otherwise. 3780 * 3781 * Throws: GException on failure. 3782 */ 3783 public bool trash(Cancellable cancellable) 3784 { 3785 GError* err = null; 3786 3787 auto p = g_file_trash(getFileStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 3788 3789 if (err !is null) 3790 { 3791 throw new GException( new ErrorG(err) ); 3792 } 3793 3794 return p; 3795 } 3796 3797 /** 3798 * Asynchronously sends @file to the Trash location, if possible. 3799 * 3800 * Params: 3801 * ioPriority = the [I/O priority][io-priority] of the request 3802 * cancellable = optional #GCancellable object, 3803 * %NULL to ignore 3804 * callback = a #GAsyncReadyCallback to call 3805 * when the request is satisfied 3806 * userData = the data to pass to callback function 3807 * 3808 * Since: 2.38 3809 */ 3810 public void trashAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3811 { 3812 g_file_trash_async(getFileStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3813 } 3814 3815 /** 3816 * Finishes an asynchronous file trashing operation, started with 3817 * g_file_trash_async(). 3818 * 3819 * Params: 3820 * result = a #GAsyncResult 3821 * 3822 * Return: %TRUE on successful trash, %FALSE otherwise. 3823 * 3824 * Since: 2.38 3825 * 3826 * Throws: GException on failure. 3827 */ 3828 public bool trashFinish(AsyncResultIF result) 3829 { 3830 GError* err = null; 3831 3832 auto p = g_file_trash_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3833 3834 if (err !is null) 3835 { 3836 throw new GException( new ErrorG(err) ); 3837 } 3838 3839 return p; 3840 } 3841 3842 /** 3843 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE. 3844 * 3845 * If @cancellable is not %NULL, then the operation can be cancelled by 3846 * triggering the cancellable object from another thread. If the operation 3847 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3848 * 3849 * When the operation is finished, @callback will be called. 3850 * You can then call g_file_unmount_mountable_finish() to get 3851 * the result of the operation. 3852 * 3853 * Deprecated: Use g_file_unmount_mountable_with_operation() instead. 3854 * 3855 * Params: 3856 * flags = flags affecting the operation 3857 * cancellable = optional #GCancellable object, 3858 * %NULL to ignore 3859 * callback = a #GAsyncReadyCallback to call 3860 * when the request is satisfied, or %NULL 3861 * userData = the data to pass to callback function 3862 */ 3863 public void unmountMountable(GMountUnmountFlags flags, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3864 { 3865 g_file_unmount_mountable(getFileStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3866 } 3867 3868 /** 3869 * Finishes an unmount operation, see g_file_unmount_mountable() for details. 3870 * 3871 * Finish an asynchronous unmount operation that was started 3872 * with g_file_unmount_mountable(). 3873 * 3874 * Deprecated: Use g_file_unmount_mountable_with_operation_finish() 3875 * instead. 3876 * 3877 * Params: 3878 * result = a #GAsyncResult 3879 * 3880 * Return: %TRUE if the operation finished successfully. 3881 * %FALSE otherwise. 3882 * 3883 * Throws: GException on failure. 3884 */ 3885 public bool unmountMountableFinish(AsyncResultIF result) 3886 { 3887 GError* err = null; 3888 3889 auto p = g_file_unmount_mountable_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3890 3891 if (err !is null) 3892 { 3893 throw new GException( new ErrorG(err) ); 3894 } 3895 3896 return p; 3897 } 3898 3899 /** 3900 * Unmounts a file of type #G_FILE_TYPE_MOUNTABLE. 3901 * 3902 * If @cancellable is not %NULL, then the operation can be cancelled by 3903 * triggering the cancellable object from another thread. If the operation 3904 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 3905 * 3906 * When the operation is finished, @callback will be called. 3907 * You can then call g_file_unmount_mountable_finish() to get 3908 * the result of the operation. 3909 * 3910 * Params: 3911 * flags = flags affecting the operation 3912 * mountOperation = a #GMountOperation, 3913 * or %NULL to avoid user interaction 3914 * cancellable = optional #GCancellable object, 3915 * %NULL to ignore 3916 * callback = a #GAsyncReadyCallback to call 3917 * when the request is satisfied, or %NULL 3918 * userData = the data to pass to callback function 3919 * 3920 * Since: 2.22 3921 */ 3922 public void unmountMountableWithOperation(GMountUnmountFlags flags, MountOperation mountOperation, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 3923 { 3924 g_file_unmount_mountable_with_operation(getFileStruct(), flags, (mountOperation is null) ? null : mountOperation.getMountOperationStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 3925 } 3926 3927 /** 3928 * Finishes an unmount operation, 3929 * see g_file_unmount_mountable_with_operation() for details. 3930 * 3931 * Finish an asynchronous unmount operation that was started 3932 * with g_file_unmount_mountable_with_operation(). 3933 * 3934 * Params: 3935 * result = a #GAsyncResult 3936 * 3937 * Return: %TRUE if the operation finished successfully. 3938 * %FALSE otherwise. 3939 * 3940 * Since: 2.22 3941 * 3942 * Throws: GException on failure. 3943 */ 3944 public bool unmountMountableWithOperationFinish(AsyncResultIF result) 3945 { 3946 GError* err = null; 3947 3948 auto p = g_file_unmount_mountable_with_operation_finish(getFileStruct(), (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 3949 3950 if (err !is null) 3951 { 3952 throw new GException( new ErrorG(err) ); 3953 } 3954 3955 return p; 3956 } 3957 }