auto_downloader

Crates.ioauto_downloader
lib.rsauto_downloader
version0.2.0
created_at2024-03-18 20:18:32.44884+00
updated_at2025-05-28 14:31:11.879103+00
descriptionRust cargo crates with auto-update functionality.
homepage
repositoryhttps://github.com/bdr-pro/auto_downloader.git
max_upload_size
id1178418
size52,982
Bader Alotaibi (BDR-Pro)

documentation

README

🚀 Auto Downloader 🚀

Hey there, fellow Rustacean! 👋 Welcome to auto_downloader, the coolest Rust project for automatically updating your app with zero hassle. Whether you're looking to keep your application up-to-date without lifting a finger or just dabbling in Rust, you've come to the right place!

What's This Project All About? 🤔

In the digital world, staying updated is the name of the game. That's why auto_downloader is here to save the day! It checks for updates, downloads the new version, and gets your app running the latest and greatest version in no time. It's like having a little robot 🤖 inside your computer, making sure you're always at the cutting edge.

Getting Started 🚀

Prerequisites

Installation

add this to your Cargo.toml file:

[dependencies]
auto_downloader = "0.2.0"

Voilà! You're now running auto_downloader. Watch it work its magic! ✨

Features 🌟

  • Automatic Updates: Checks for updates and downloads them without you having to move a muscle.
  • Secure: Verifies download integrity to keep the nasties away. 🛡️
  • Cross-Platform Goodness: Works on all your favorite platforms. 🖥️ 🍏 🪟

How to Use 🛠️

Honestly? Just let it do its thing! auto_downloader works in the background, ensuring your application is always up to date. For those who like to tinker, dive into the src folder to see how the magic happens. Who knows, you might find some cool ideas for your next Rust project!

Contributing 🤝

Want to contribute? Awesome! Feel free to fork the repo, make your changes, and submit a pull request. All ideas and contributions are welcome. Let's make auto_downloader even better together!

License 📜

This project is proudly licensed under the MIT License. See the LICENSE file for details.

Final Words 📢

Thanks for checking out auto_downloader! If you like what you see, give it a star ⭐, and share it with your friends. Happy coding, and may your applications always be up-to-date!

Example

{
    "version": "1.0.1",
    "download_url": "https://example.com/your_application_1.0.1.exe",
    "sha256_checksum": "d73d56b328d5a8ffdf27430edb4d9d68e1e2a8f2c3e2656c672e4f6b76153a2b",
    "app_name": "your_application.exe"
}

Code

  • in updater.rs
use auto_downloader;
use std::{env, fs, process::Command, thread::sleep, time::Duration};

fn main() {
    let info_url = "https://example.com/version_info.json";

    let Ok(version_info) = common::get_version_info(info_url) else {
        eprintln!("Failed to get update info.");
        return;
    };

    let temp_path = env::temp_dir().join("update_new.bin");
    println!("⬇️ Downloading new version...");
    if let Err(e) = common::download_new_version(&version_info.download_url, &temp_path) {
        eprintln!("Download failed: {}", e);
        return;
    }

    println!("🔒 Verifying checksum...");
    match common::compute_file_sha256(&temp_path) {
        Ok(hash) if hash != version_info.sha256_checksum => {
            eprintln!("❌ Checksum mismatch. Aborting update.");
            return;
        }
        Ok(_) => println!("✅ Checksum verified."),
        Err(e) => {
            eprintln!("Error computing checksum: {}", e);
            return;
        }
    }

    let app_path = env::current_dir().unwrap().join(&version_info.app_name);

    // Wait for the main app to exit
    println!("⏳ Waiting for app to close...");
    sleep(Duration::from_secs(1));

    if cfg!(target_os = "windows") {
        fs::remove_file(&app_path).ok();
    }

    println!("🔄 Replacing binary...");
    fs::rename(&temp_path, &app_path).expect("Failed to replace binary");

    println!("🚀 Launching new version...");
    Command::new(&app_path)
        .spawn()
        .expect("Failed to launch new version");
}


  • ""in main.rs"

use auto_downloader::get_version_info;
use std::process::Command;

fn main() {
    let current_version = "1.0.0";
    let info_url = "https://example.com/version_info.json";

    match get_version_info(info_url) {
        Ok(info) if info.version != current_version => {
            println!("Update available. Launching updater...");
            Command::new("updater")
                .spawn()
                .expect("Failed to launch updater");
            std::process::exit(0);
        }
        Ok(_) => println!("✅ You're up to date!"),
        Err(e) => eprintln!("Failed to check version: {}", e),
    }

    // Your real app logic goes here
    println!("🧠 Main app is running...");
}



/*


{
    "version": "1.0.1",
    "download_url": "https://example.com/your_application_1.0.1.exe",
    "sha256_checksum": "d73d56b328d5a8ffdf27430edb4d9d68e1e2a8f2c3e2656c672e4f6b76153a2b",
    "app_name": "your_application.exe"
}




*/

Authors

👤 Bader alotaibi @ baderalotaibi3@gmail.com

Show your support

Give a ⭐️ if you like this project!

Commit count: 4

cargo fmt