Exemple #1
0
    def desktop_integration(self, desktop_dir=None, restore=False):
        """Overwrite desktop integration"""
        user = os.getenv("USER")
        user_dir = os.path.join(self.path, "drive_c/users/", user)
        desktop_folders = self.get_desktop_folders()

        if desktop_dir:
            desktop_dir = os.path.expanduser(desktop_dir)
        else:
            desktop_dir = user_dir

        if system.path_exists(user_dir):
            # Replace or restore desktop integration symlinks
            for i, item in enumerate(desktop_folders):
                path = os.path.join(user_dir, item)
                old_path = path + ".winecfg"

                if os.path.islink(path):
                    if not restore:
                        os.unlink(path)
                elif os.path.isdir(path):
                    try:
                        os.rmdir(path)
                    # We can't delete nonempty dir, so we rename as wine do.
                    except OSError:
                        os.rename(path, old_path)

                if restore and not os.path.isdir(path):
                    os.symlink(xdgshortcuts.get_xdg_entry(DESKTOP_XDG[i]),
                               path)
                    # We don't need all the others process of the loop
                    continue

                if desktop_dir != user_dir:
                    try:
                        src_path = os.path.join(desktop_dir, item)
                    except TypeError:
                        # There is supposedly a None value in there
                        # The current code shouldn't allow that
                        # Just raise a exception with the values
                        raise RuntimeError(
                            "Missing value desktop_dir=%s or item=%s" %
                            (desktop_dir, item))

                    os.makedirs(src_path, exist_ok=True)
                    os.symlink(src_path, path)
                else:
                    # We use first the renamed dir, otherwise we make it.
                    if os.path.isdir(old_path):
                        os.rename(old_path, path)
                    else:
                        os.makedirs(path, exist_ok=True)

            # Security: Remove other symlinks.
            for item in os.listdir(user_dir):
                path = os.path.join(user_dir, item)
                if item not in DEFAULT_DESKTOP_FOLDERS and os.path.islink(
                        path):
                    os.unlink(path)
                    os.makedirs(path)
Exemple #2
0
    def desktop_integration(self, desktop_dir=None, restore=False):
        """Overwrite desktop integration"""
        DESKTOP_FOLDERS = []

        user = os.getenv("USER")
        user_dir = os.path.join(self.path, "drive_c/users/", user)

        for key in DESKTOP_KEYS:
            folder = self.get_registry_key(
                self.hkcu_prefix +
                "/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders",
                key,
            )
            DESKTOP_FOLDERS.append(folder[folder.rfind("\\") + 1:])

        if not desktop_dir:
            desktop_dir = user_dir
        else:
            desktop_dir = os.path.expanduser(desktop_dir)

        if system.path_exists(user_dir):
            # Replace or restore desktop integration symlinks
            for i, item in enumerate(DESKTOP_FOLDERS):
                path = os.path.join(user_dir, item)
                old_path = path + ".winecfg"

                if os.path.islink(path):
                    if not restore:
                        os.unlink(path)
                elif os.path.isdir(path):
                    try:
                        os.rmdir(path)
                    # We can't delete nonempty dir, so we rename as wine do.
                    except OSError:
                        os.rename(path, old_path)

                if restore and not os.path.isdir(path):
                    os.symlink(xdgshortcuts.get_xdg_entry(DESKTOP_XDG[i]),
                               path)
                    # We don't need all the others process of the loop
                    continue

                if desktop_dir != user_dir:
                    src_path = os.path.join(desktop_dir, item)
                    os.makedirs(src_path, exist_ok=True)
                    os.symlink(src_path, path)
                else:
                    # We use first the renamed dir, otherwise we make it.
                    if os.path.isdir(old_path):
                        os.rename(old_path, path)
                    else:
                        os.makedirs(path, exist_ok=True)

            # Security: Remove other symlinks.
            for item in os.listdir(user_dir):
                path = os.path.join(user_dir, item)
                if item not in DESKTOP_FOLDERS and os.path.islink(path):
                    os.unlink(path)
                    os.makedirs(path)
Exemple #3
0
    def desktop_integration(self, desktop_dir=None, restore=False):  # noqa: C901
        """Overwrite desktop integration"""
        # pylint: disable=too-many-branches
        # TODO: reduce complexity (18)
        user = os.getenv("USER") or 'lutrisuser'
        user_dir = os.path.join(self.path, "drive_c/users/", user)
        desktop_folders = self.get_desktop_folders()
        desktop_dir = os.path.expanduser(desktop_dir) if desktop_dir else user_dir

        if system.path_exists(user_dir):
            # Replace or restore desktop integration symlinks
            for i, item in enumerate(desktop_folders):
                path = os.path.join(user_dir, item)
                old_path = path + ".winecfg"

                if os.path.islink(path):
                    if not restore:
                        os.unlink(path)
                elif os.path.isdir(path):
                    try:
                        os.rmdir(path)
                    # We can't delete nonempty dir, so we rename as wine do.
                    except OSError:
                        os.rename(path, old_path)

                # if we want to create a symlink and one is already there, just
                # skip to the next item.  this also makes sure the elif doesn't
                # find a dir (isdir only looks at the target of the symlink).
                if restore and os.path.islink(path):
                    continue
                if restore and not os.path.isdir(path):
                    src_path = get_xdg_entry(DESKTOP_XDG[i])
                    if not src_path:
                        logger.error("No XDG entry found for %s, launcher not created", DESKTOP_XDG[i])
                    else:
                        os.symlink(src_path, path)
                    # We don't need all the others process of the loop
                    continue

                if desktop_dir != user_dir:
                    try:
                        src_path = os.path.join(desktop_dir, item)
                    except TypeError:
                        # There is supposedly a None value in there
                        # The current code shouldn't allow that
                        # Just raise a exception with the values
                        raise RuntimeError("Missing value desktop_dir=%s or item=%s" % (desktop_dir, item))

                    os.makedirs(src_path, exist_ok=True)
                    os.symlink(src_path, path)
                else:
                    # We use first the renamed dir, otherwise we make it.
                    if os.path.isdir(old_path):
                        os.rename(old_path, path)
                    else:
                        os.makedirs(path, exist_ok=True)
Exemple #4
0
    def desktop_integration(self, desktop_dir=None, restore=False):
        """Overwrite desktop integration"""
        user = os.getenv("USER")
        user_dir = os.path.join(self.path, "drive_c/users/", user)
        _desktop_folders = self.get_desktop_folders()
        if _desktop_folders:
            DESKTOP_FOLDERS = _desktop_folders  # pylint: disable=invalid-name

        if not desktop_dir:
            desktop_dir = user_dir
        else:
            desktop_dir = os.path.expanduser(desktop_dir)

        if system.path_exists(user_dir):
            # Replace or restore desktop integration symlinks
            for i, item in enumerate(DESKTOP_FOLDERS):
                path = os.path.join(user_dir, item)
                old_path = path + ".winecfg"

                if os.path.islink(path):
                    if not restore:
                        os.unlink(path)
                elif os.path.isdir(path):
                    try:
                        os.rmdir(path)
                    # We can't delete nonempty dir, so we rename as wine do.
                    except OSError:
                        os.rename(path, old_path)

                if restore and not os.path.isdir(path):
                    os.symlink(xdgshortcuts.get_xdg_entry(DESKTOP_XDG[i]), path)
                    # We don't need all the others process of the loop
                    continue

                if desktop_dir != user_dir:
                    src_path = os.path.join(desktop_dir, item)
                    os.makedirs(src_path, exist_ok=True)
                    os.symlink(src_path, path)
                else:
                    # We use first the renamed dir, otherwise we make it.
                    if os.path.isdir(old_path):
                        os.rename(old_path, path)
                    else:
                        os.makedirs(path, exist_ok=True)

            # Security: Remove other symlinks.
            for item in os.listdir(user_dir):
                path = os.path.join(user_dir, item)
                if item not in DESKTOP_FOLDERS and os.path.islink(path):
                    os.unlink(path)
                    os.makedirs(path)