|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using System.Windows.Forms; |
| 8 | +using Microsoft.VisualBasic.FileIO; |
| 9 | + |
| 10 | +namespace Launchbox_Local_Scraper |
| 11 | +{ |
| 12 | + class FileToBeCopied |
| 13 | + { |
| 14 | + // RoboCommand backup;/// <summary> |
| 15 | + /// ///////////////////////////////////////////////////////////////////// |
| 16 | + /// </summary> |
| 17 | + private string platLBVidFolder; |
| 18 | + private string platOriginalVidFolder; |
| 19 | + private string gameName; |
| 20 | + private string ext; |
| 21 | + private string fileToCopy; |
| 22 | + private bool renameOriginalVideos; |
| 23 | + private bool weAreDoingArcade; |
| 24 | + private string romName; |
| 25 | + |
| 26 | + public FileToBeCopied(string platformLaunchboxVideoFolder, string platformOriginalVideoFolder, string gameName, string extension, |
| 27 | + string fileToCopy, bool renameOriginalVideos, bool weAreDoingArcade, string romFileName) |
| 28 | + { |
| 29 | + this.platLBVidFolder = platformLaunchboxVideoFolder; |
| 30 | + this.platOriginalVidFolder = platformOriginalVideoFolder; |
| 31 | + this.gameName = gameName; |
| 32 | + this.ext = extension; |
| 33 | + this.fileToCopy = fileToCopy; |
| 34 | + this.renameOriginalVideos = renameOriginalVideos; |
| 35 | + this.weAreDoingArcade = weAreDoingArcade; |
| 36 | + this.romName = romFileName; |
| 37 | + } |
| 38 | + |
| 39 | + private string concatenateVideoPath(string videoFolder) |
| 40 | + { |
| 41 | + string correctFileName; |
| 42 | + |
| 43 | + if (weAreDoingArcade) |
| 44 | + correctFileName = romName; |
| 45 | + else |
| 46 | + correctFileName = generalUtils.removeInvalidCharsWindowsFileSystem(gameName); |
| 47 | + |
| 48 | + return Path.GetFullPath(videoFolder + @"\" + (correctFileName) + ext); |
| 49 | + } |
| 50 | + |
| 51 | + public void processFileAsyncTask() |
| 52 | + { |
| 53 | + generalUtils.createFolderIfDoesntExist(platLBVidFolder); |
| 54 | + |
| 55 | + try |
| 56 | + { |
| 57 | + File.Copy(fileToCopy, concatenateVideoPath(platLBVidFolder)); |
| 58 | + |
| 59 | + if (renameOriginalVideos && ! weAreDoingArcade) //only rename videos if they havent got mame filenames, because user might make mistake... |
| 60 | + { |
| 61 | + string newFilePath = concatenateVideoPath(platOriginalVidFolder); |
| 62 | + |
| 63 | + if (!newFilePath.ToUpper().Equals(fileToCopy.ToUpper())) //if the new file name is different than the original, all in upercase because windows is stupid |
| 64 | + { |
| 65 | + Directory.Move(fileToCopy, newFilePath); //renames original file to correct name |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + catch (Exception except) |
| 71 | + { |
| 72 | + MessageBox.Show( |
| 73 | + "Couldn't create file.\n Check if you have permissions\n. Exception:" + except.Message.ToString()); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// copies file to launchbox folder and renames original file if renameOriginalVideos is true |
| 79 | + /// </summary> |
| 80 | + public void processFile() |
| 81 | + { |
| 82 | + // processFileAsyncTask(); |
| 83 | + //do async because we don't want to wait for files to copy... |
| 84 | + Task task = new Task(new Action(processFileAsyncTask)); |
| 85 | + task.Start(); |
| 86 | + } |
| 87 | + |
| 88 | + public string getNewOriginalFilePath() |
| 89 | + { |
| 90 | + return concatenateVideoPath(platOriginalVidFolder); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments