Giter VIP home page Giter VIP logo

libtrashcan's Introduction

libtrashcan

libtrashcan is a cross-platform C library for moving files and directories to the trashcan.

Supported Operating Systems

Build Status Operating System
Linux Build Status Linux
BSD Build Status FreeBSD, OpenBSD, NetBSD
Windows Build Status Windows Vista, Windows Server 2008 and newer
macOS Build Status macOS

Why is this useful?

When you're implementing user interaction for viewing, selecting, loading and creating files you may also want to offer the functionality to delete files. Using POSIX specified functions for cross-platform development may seem sensible, however remove() and rmdir() happen to permanently delete files and directories. This is likely not the behavior a user of your program would anticipate even more so if there aren't any warnings. In order to ease development of cross-platform C applications this library implements the soft delete functionality for you. It also helps with operating systems where the C interface isn't well documented, like for instance with Windows' IFileOperation interface.

How does the library implement a trashcan?

For Linux and *BSD the library implements the FreeDesktop.org trash specification v1.0. On Windows our implementation uses the IFileOperation interface and also handles COM initialization. MacOS already has a simple way to trash files using the NSFileManager which is wrapped in a function as well.

API

The function int trashcan_soft_delete(const char *path) is provided on all platforms. It takes a path to a file or directory, tries to move it to the trashcan and returns a status code. Additional platform dependent functions with different signatures may be provided, e.g. to control COM initialization on Windows. The complete API is documented in the trashcan.h file. For an example application that uses libtrashcan take a look at example.c.

All functions for soft deletion return a status code which can be converted into a status message using const char* trashcan_status_msg(int status_code). Any status code other than zero means that an error occured.

Compilation

In order to use libtrashcan you need to include trashcan.h in your source code, build and link the library. An example projects is provided that shows how to do that using CMake. Using CMake is not a requirement for your project you can use any build tools you prefer. If you build your own application on macOS and don't use our provided CMakeLists.txt then you need to link and include the header files of CoreFoundation and Cocoa as well.

The example project is a CLI application that takes a path to a file or directory as argument and tries to move it to the trash. It can be build by executing the following commands on your terminal/shell/command line if you have CMake and a compiler is installed:

mkdir build
cd ./build
cmake ..
cmake --build . --config Release

License

Libtrashcan is licensed under the MIT License. This license is compatible with GPL.

Contribute

The library is in early development and making sure that it reaches a mature state is a core goal. If you'd like to contribute check the issue tracker or submit pull requests for improvements. In particular I'd be grateful for contributions regarding:

  • Identifying cross-platform issues
  • Stability / Reliability
  • Security

libtrashcan's People

Contributors

robertguetzkow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.