Paint.DefaultImageInstaller.InstallDefaultImages C# (CSharp) Method

InstallDefaultImages() public method

Installs the default images.
public InstallDefaultImages ( ) : void
return void
        public void InstallDefaultImages()
        {
            string imageFolder = this.deviceScale == 1 ? "StandardResolution" : "RetinaResolution";
            var searchFolder = Path.Combine("Content/DefaultImages", imageFolder);

            var folderList = Directory.EnumerateDirectories(searchFolder);
            foreach (var folder in folderList)
            {
                var pictureID = Path.GetFileName(folder);
                var imageDestination = Path.Combine(this.masterImagePath, String.Format("{0}.JPG", pictureID));
                var imageSource = Path.Combine(folder, String.Format("{0}.JPG", pictureID));

                if (!File.Exists(imageDestination) && File.Exists(imageSource))
                {
                    // Copy the master jpg image
                    File.Copy(imageSource, imageDestination);
                }

                var destinationImageDataFolder = Path.Combine(this.imageDataPath, pictureID);
                if (!File.Exists(destinationImageDataFolder))
                {
                    // Ceate a folder for the data info file and undo/redo render buffer files...
                    Directory.CreateDirectory(destinationImageDataFolder);
                }

                foreach (string fileToCopy in new string[] { "DATA.INF", "0.REC", "0.PNG" })
                {
                    // ... and then copy the data in.
                    var sourceDataFile = Path.Combine(folder, fileToCopy);
                    var destinationDataFile = Path.Combine(destinationImageDataFolder, fileToCopy);

                    if (!File.Exists(destinationDataFile) && File.Exists(sourceDataFile))
                    {
                        File.Copy(sourceDataFile, destinationDataFile);
                    }
                }
            }
        }

Usage Example

        /// <summary>
        /// Checks if this is the initial installation - and if so then performs some initial one off set-up
        /// </summary>
        private void CheckInitialInstallation()
        {
            if (!File.Exists(this.versionDataFilePath))
            {
                // This is the very first time the app has ever been run so let's copy in some default images...
                var defaultImageInstaller = new DefaultImageInstaller(this.imageDataPath, this.masterImagePath, this.deviceScale);
                defaultImageInstaller.InstallDefaultImages();
            }

            this.WriteVersionFile();
        }