public static ByteSize GetSize(this FileSystemPath path)
 {
     if (path.FileExists)
     {
         return(ByteSize.FromBytes(path.GetFileInfo().Length));
     }
     else if (path.DirectoryExists)
     {
         return(GetDirectorySize(path));
     }
     else
     {
         return(default);
        public static FileSystemInfo GetFileSystemInfo(this FileSystemPath path)
        {
            switch (path.FileSystemType)
            {
            case FileSystemType.File:
                return(path.GetFileInfo());

            case FileSystemType.Directory:
                return(path.GetDirectoryInfo());

            case FileSystemType.Relative:
            case FileSystemType.Unknown:
            default:
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Runs the basic startup, such as handling launch arguments
        /// </summary>
        /// <returns>The task</returns>
        private async Task BasicStartupAsync()
        {
            // Track changes to the user data
            PreviousLinkItemStyle  = Data.LinkItemStyle;
            PreviousBackupLocation = Data.BackupLocation;

            // Subscribe to when to refresh the jump list
            RCPServices.App.RefreshRequired += (s, e) =>
            {
                if (e.GameCollectionModified || e.GameInfoModified || e.JumpListModified)
                {
                    RefreshJumpList();
                }

                return(Task.CompletedTask);
            };
            Services.Data.CultureChanged += (s, e) => RefreshJumpList();

            // Subscribe to when the app has finished setting up
            StartupComplete += App_StartupComplete_GameFinder_Async;
            StartupComplete += App_StartupComplete_Miscellaneous_Async;

            // Check for reset argument
            if (Services.Data.Arguments.Contains("-reset"))
            {
                RCPServices.Data.Reset();
            }

            // Check for user level argument
            if (Services.Data.Arguments.Contains("-ul"))
            {
                try
                {
                    string ul = Services.Data.Arguments[Services.Data.Arguments.FindItemIndex(x => x == "-ul") + 1];
                    Data.UserLevel = Enum.Parse(typeof(UserLevel), ul, true).CastTo <UserLevel>();
                }
                catch (Exception ex)
                {
                    ExceptionExtensions.HandleError(ex, "Setting user level from args");
                }
            }

            // NOTE: Starting with the updater 3.0.0 (available from 4.5.0) this is no longer used. It must however be maintained for legacy support (i.e. updating to version 4.5.0+ using an updater below 3.0.0)
            // Check for updater install argument
            if (Services.Data.Arguments.Contains("-install"))
            {
                try
                {
                    FileSystemPath updateFile = Services.Data.Arguments[Services.Data.Arguments.FindItemIndex(x => x == "-install") + 1];
                    if (updateFile.FileExists)
                    {
                        updateFile.GetFileInfo().Delete();
                        RL.Logger?.LogInformationSource($"The updater was deleted");
                    }
                }
                catch (Exception ex)
                {
                    ExceptionExtensions.HandleError(ex, "Deleting updater");
                }
            }

            // Update the application path
            FileSystemPath appPath = Assembly.GetEntryAssembly()?.Location;

            if (appPath != Data.ApplicationPath)
            {
                Data.ApplicationPath = appPath;

                RL.Logger?.LogInformationSource("The application path has been updated");
            }

            // Deploy additional files
            await RCPServices.App.DeployFilesAsync(false);

            // Show first launch info
            if (Data.IsFirstLaunch)
            {
                // Close the splash screen
                CloseSplashScreen();

                new FirstLaunchInfoDialog().ShowDialog();
                Data.IsFirstLaunch = false;
            }

            LogStartupTime("Validating games");

            // Validate the added games
            await ValidateGamesAsync();

            LogStartupTime("Finished validating games");
        }