Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for moving games between disks #532

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

toxicrecker
Copy link

@toxicrecker toxicrecker commented Jan 7, 2023

Used shutil.move() instead of os.rename() to add support for moving games to different disks. May or may not copy metadata but it should be fine since file metadata isn't really necessary as far as I am aware.

Used `[shutil.move()](https://docs.python.org/3/library/shutil.html#shutil.move)` instead of `os.rename()` to add support for moving games to different disks.
This is a helper function for implementing a progress indication in the moving games between disks functionality
Moving between disks can take a long time and before there was no progress indication so the user might think that the program was stuck but I have added it now
legendary/cli.py Outdated
Comment on lines 2515 to 2519
choice = get_boolean_choice(f'Moving files to another drive can cause errors when running the game, '
f'however, it is unlikely to happen. Do you still wish to continue? (default=no)', default=False)
if not choice:
logger.info(f'To move it without a risk move the folder manually to {new_path} '
f'and run "legendary move {app_name} "{args.new_path}" --skip-move"')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels somewhat vague. What exactly are those errors/risks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't know. I thought that because this was not done before there must be a reason for it. On python docs I found that this function may or may not copy the metadata so I thought that must've been the reason but I've had 0 problems after trying it with 3-4 games so I'm sure it can be removed.

@toxicrecker
Copy link
Author

I think I'm done with this PR for now so we can discuss anything further (if needed) or it could be merged.

@actualdankcoder
Copy link

actualdankcoder commented Jan 13, 2023

This seems like a genuinely useful addition

but I've had 0 problems after trying it with 3-4 games so I'm sure it can be removed.

I don't think there are going to any errors/risks with moving most games since they most likely use relative paths

@toxicrecker
Copy link
Author

I worked on making moving games resumable and cleaned up the code.

@derrod
Copy link
Owner

derrod commented May 27, 2023

Thanks but I don't think I want to add more features at this time. There's a lot of refactoring that needs to be done and it'll break all PRs anyway. But I'll leave it open for now.

@buswedg
Copy link

buswedg commented Oct 22, 2023

I'd support this PR. Relatively small change, and hard to see any major risk.

The code to track progress looks pretty complicated however. Can't just use something like tqdm?And what about a comparison of files after the copy to be sure. Perhaps using something like the below.

import os
from tqdm import tqdm
from pathlib import Path
import shutil
import filecmp

def copytree_with_progress(source, destination):
    total_size = sum(os.path.getsize(f) for f in Path(source).rglob('*'))

    def copy_with_progress(src, dst):
        shutil.copy2(src, dst)
        progress_bar.update(os.path.getsize(src))

    try:
        with tqdm(total=total_size, unit='B', unit_scale=True) as progress_bar:
            shutil.copytree(source, destination, copy_function=copy_with_progress, ignore=shutil.ignore_patterns(''))
            return True

    except Exception as e:
        print(f"Failed to copy files. Exception: {e}")
        return False

copytree_with_progress(old_install_dir, new_install_dir)

dircmp = filecmp.dircmp(old_install_dir, new_install_dir, ignore=None)

if not dircmp.left_only and not dircmp.right_only:
    print("Copy successful, updating manifest and removing old install location.")

@iamtherobin
Copy link

Was just looking for this feature to move a game and found this ticket. Is this going to be implemented?

If not, how to I go about moving my game? Should I just copy the game folder to another drive and then import into legendary again?

@buswedg
Copy link

buswedg commented Nov 2, 2023

Was just looking for this feature to move a game and found this ticket. Is this going to be implemented?

If not, how to I go about moving my game? Should I just copy the game folder to another drive and then import into legendary again?

I wrote something quick and dirty which serves my needs (https://github.com/buswedg/epic-library-manager), including being able to move to a mounted network location. Did the same for Amazon Games and Steam as well. I've got a todo to look at the sync functionality on legendary and nile at some point, to see how its config (and the launchers manifest) can be updated post-move. But I've got a lot on at the moment, so not sure when I'll be able to get this done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants