Example #1
0
 public void ImportFiles(string[] gameFilenames, string[] diskFilenames, FileCopyProgress callback)
 {
     for (int i = 0; i < diskFilenames.Length; i++)
     {
         ImportFile(gameFilenames[i], diskFilenames[i], callback);
     }
 }
Example #2
0
        private static void DownloadProgress(object sender, System.Net.DownloadProgressChangedEventArgs e)
        {
            double percent    = ((FileTransferedIndex * 100.0) + e.ProgressPercentage) / TotalPercent;
            int    percentage = (int)(percent * 100);

            FileCopyProgress?.Invoke(percentage > 100 ? 100 : percentage);
        }
Example #3
0
        public void ImportFile(string gameFilename, string diskFilename, FileCopyProgress callback)
        {
            Node     node = ISO.DataPartition.Root.Root;
            FileNode file = (node as DirectoryNode).Navigate(gameFilename) as FileNode;

            if (file == null)
            {
                return;
            }

            FileStream f = new FileStream(diskFilename, FileMode.Create, FileAccess.Write);

            file.Data.Position = 0;
            Util.StreamCopy(f, file.Data, file.Size);
            f.Close();
        }
Example #4
0
        public async Task <IFile> CopyToAsync(
            IFolder folder,
            Stream fileContent,
            string fileName,
            CancellationToken?token = null,
            IProgress <FileCopyProgress> progress = null)
        {
            var state = new FileCopyProgress {
                TotalSize = fileContent.Length, Name = fileName
            };

            progress?.Report(state);
            var targetPath = Path.Combine(folder.Id, fileName);

            using (var stream = new FileStream(targetPath, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                var bufferSize = 1024 * 1024;
                var buffer     = new byte[bufferSize];
                int count;
                while ((count = token.HasValue
                    ? await fileContent.ReadAsync(buffer, 0, buffer.Length, token.Value)
                    : await fileContent.ReadAsync(buffer, 0, buffer.Length)) != 0)
                {
                    if (token.HasValue)
                    {
                        await stream.WriteAsync(buffer, 0, count, token.Value);
                    }
                    else
                    {
                        await stream.WriteAsync(buffer, 0, count);
                    }

                    state.CopiedSize += count;
                    progress?.Report(state);
                }
            }

            return(new DriveFile(targetPath, fileName, Root, DriveType, state.CopiedSize));
        }
Example #5
0
        public void ExportFile(string diskFilename, string gameFilename, FileCopyProgress callback)
        {
            string outpath = Path.Combine(FileBasePath, gameFilename.StartsWith("/") ? gameFilename.Substring(1) : gameFilename);

            Directory.CreateDirectory(Path.GetDirectoryName(outpath));

            FileStream fin  = new FileStream(diskFilename, FileMode.Open, FileAccess.Read);
            FileStream fout = new FileStream(outpath, FileMode.Create, FileAccess.Write);

            Util.StreamCopy(fout, fin);
            fin.Close();
            fout.Close();

            string flistpath = Path.Combine(BasePath, "riivolution");

            Directory.CreateDirectory(flistpath);
            flistpath = Path.Combine(flistpath, "theghost.xml");
            FileStream   flist  = new FileStream(flistpath, FileMode.Create);
            StreamWriter writer = new StreamWriter(flist, Util.Encoding);

            writer.WriteLine("<wiidisc version=\"1\">");
            writer.WriteLine("<id game=\"RGH\" />");                     // TODO: Aerosmith?
            writer.WriteLine("<options>");
            writer.WriteLine("<section name=\"TheGHOST\">");
            writer.WriteLine("<option name=\"TheGHOST\">");
            writer.WriteLine("<choice name=\"Enabled\">");
            writer.WriteLine("<patch id=\"theghostfolder\" />");
            writer.WriteLine("</choice>");
            writer.WriteLine("</option>");
            writer.WriteLine("</section>");
            writer.WriteLine("</options>");
            writer.WriteLine("<patch id=\"theghostfolder\">");
            writer.WriteLine("<folder disc=\"/\" external=\"/theghost\" create=\"true\" />");
            writer.WriteLine("</patch>");
            writer.WriteLine("</wiidisc>");
            writer.Close();
        }
Example #6
0
        /// <summary>
        /// Writes all modified files that have been read with FileImport or added with FileAddNew, skips dats when wads failed
        /// </summary>
        /// <param name="callback"></param>
        /// <returns>List of failed files</returns>
        public GameFile[] ExportAllChangedSmart(FileCopyProgress callback)
        {
            List<GameFile> other = new List<GameFile>();
            List<GameFile> wad = new List<GameFile>();
            List<GameFile> dat = new List<GameFile>();
            List<GameFile> failed = new List<GameFile>();
            List<GameFile> skipped = new List<GameFile>();

            //don't get TheGHOST files
            foreach (GameFile gf in _project.FileManager.ChangedFiles())
            {
                switch (gf.Type)
                {
                    case GameFileType.Wad:
                        wad.Add(gf);
                        break;
                    case GameFileType.Dat:
                        dat.Add(gf);
                        break;
                    default:
                        other.Add(gf);
                        break;
                }
            }

            //now get TheGHOST files.  This means if we run out of room, it will hopefully be these files that fail

            _project.FileManager.Export(other.ToArray(), delegate (string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(other[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });

            if (failed.Count == 0)
            {
                _project.FileManager.Export(wad.ToArray(), delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                    {
                        if (!success)
                        {
                            failed.Add(wad[fileNo]);
                            skipped.Add(dat[fileNo - skipped.Count]);
                            dat.RemoveAt(fileNo - (skipped.Count - 1));
                        }
                        if (callback != null)
                            callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                    });

                _project.FileManager.Export(dat.ToArray(), delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(dat[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });

                //raise event for skipped files
                for (int i = 0; i < skipped.Count; i++)
                {
                    if (callback != null)
                        callback(skipped[i].GameName, skipped[i].LocalName, i, skipped.Count, 100, false);
                }
            }

            return failed.ToArray();
        }
Example #7
0
        /// <summary>
        /// Writes all modified files that have been read with FileImport or added with FileAddNew
        /// </summary>
        /// <returns>List of failed files</returns>
        public GameFile[] ExportAllChanged(FileCopyProgress callback)
        {
            GameFile[] _gfs = this.ChangedFiles();
            List<GameFile> failed = new List<GameFile>();

            if (_gfs.Length != 0)
                this.Export(_gfs, delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                    {
                        if (!success)
                            failed.Add(_gfs[fileNo]);
                        if (callback != null)
                            callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                    });

            return failed.ToArray();
        }
Example #8
0
        /// <summary>
        /// Write a single files to the game
        /// </summary>
        /// <param name="gameFile"></param>
        /// <returns>List of failed files</returns>
        public GameFile[] Export(GameFile gameFile, FileCopyProgress callback)
        {
            List<GameFile> failed = new List<GameFile>();
            List<GameFile> gf = new List<GameFile>();
            _fileCopy.SetSourcePath(_gameLocation);
            _fileCopy.ExportFile(gameFile.LocalName, gameFile.GameName, delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(gf[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });
            gameFile.UpdateLocalDateTime();

            return failed.ToArray();
        }
Example #9
0
        /// <summary>
        /// Write files to the game
        /// </summary>
        /// <param name="gameFiles"></param>
        /// <returns>List of failed files</returns>
        public GameFile[] Export(GameFile[] gameFiles, FileCopyProgress callback)
        {
            List<GameFile> failed = new List<GameFile>();
            _fileCopy.SetSourcePath(_gameLocation);
            _fileCopy.ExportFiles(GameFile.CreateLocalArray(gameFiles), GameFile.CreateGameArray(gameFiles), delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(gameFiles[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });
            foreach (GameFile gf in gameFiles)
                gf.UpdateLocalDateTime();

            return failed.ToArray();
        }
Example #10
0
 private void DownloadProgress(object sender, DownloadProgressChangedEventArgs e)
 {
     FileCopyProgress?.Invoke(e.ProgressPercentage);
 }
Example #11
0
 /// <summary>
 /// Export a files from TheGHOST to a Wii ISO
 /// </summary>
 /// <param name="diskFilenames">Local disk path and filenames</param>
 /// <param name="gameFilenames">Lowercase path and filenames seperated by \</param>
 void IPluginFileCopy.ExportFiles(string[] diskFilenames, string[] gameFilenames, FileCopyProgress callback)
 {
     replace(gameFilenames, diskFilenames, callback);
 }
Example #12
0
        /// <summary>
        /// Read a single file from the game
        /// </summary>
        /// <param name="gameFile"></param>
        /// <returns>List of failed files</returns>
        public GameFile[] Import(GameFile gameFile, FileCopyProgress callback)
        {
            List<GameFile> failed = new List<GameFile>();
            List<GameFile> gf = new List<GameFile>();
            _fileCopy.SetSourcePath(_gameLocation);
            _fileCopy.ImportFile(gameFile.GameName, gameFile.LocalName, delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(gf[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });

            if (!io.File.Exists(gameFile.LocalName))
                throw new ApplicationException("Failed to import files from the game source.");

            _files.Add(gameFile.GameName, gameFile);

            return failed.ToArray();
        }
Example #13
0
        /// <summary>
        ///     复制整个文件夹
        /// </summary>
        /// <param name="Source">源文件夹路径</param>
        /// <param name="Destination">目标文件夹路径</param>
        /// <param name="Recursive">是否递归复制子文件夹</param>
        /// <param name="Options">复制的配置</param>
        /// <param name="fileCopyProgressCallback">文件拷贝进度,当复制完一个文件之后,会回调一次该函数</param>
        public static void CopyDirectory(string Source,
                                         string Destination,
                                         bool Recursive      = true,
                                         CopyOptions Options = CopyOptions.CopyAlways,
                                         FileCopyProgress fileCopyProgressCallback = null
                                         )
        {
            if (string.IsNullOrEmpty(Source))
            {
                throw new ArgumentNullException("Source");
            }
            if (string.IsNullOrEmpty(Destination))
            {
                throw new ArgumentNullException("Destination");
            }
            if (!DirectoryExists(Source))
            {
                throw new ArgumentException("Source directory does not exist");
            }

            DirectoryInfo SourceInfo      = new DirectoryInfo(Source);
            DirectoryInfo DestinationInfo = new DirectoryInfo(Destination);

            CreateDirectory(Destination);
            FileInfo[] Files = GetFileList(Source);

            bool isCanCopy = true;

            foreach (FileInfo File in Files)
            {
                string filePath = Path.Combine(DestinationInfo.FullName, File.Name);

                if (Options == CopyOptions.CopyAlways)
                {
                    //File.CopyTo(Path.Combine(DestinationInfo.FullName, File.Name), true);
                }
                else if (Options == CopyOptions.CopyIfNewer)
                {
                    if (FileExists(filePath))
                    {
                        FileInfo FileInfo = new FileInfo(filePath);
                        if (FileInfo.LastWriteTime.CompareTo(File.LastWriteTime) > 0)
                        {
                            isCanCopy = false;
                            //File.CopyTo(Path.Combine(DestinationInfo.FullName, File.Name), true);
                        }
                    }
                    else
                    {
                        isCanCopy = true;
                        //File.CopyTo(Path.Combine(DestinationInfo.FullName, File.Name), true);
                    }
                }
                else if (Options == CopyOptions.DoNotOverwrite)
                {
                    if (FileExists(filePath))
                    {
                        isCanCopy = false;
                    }
                    //File.CopyTo(Path.Combine(DestinationInfo.FullName, File.Name), false);
                }

                if (isCanCopy)
                {
                    Exception error = null;
                    try
                    {
                        File.CopyTo(filePath, true);
                    }
                    catch (Exception ex)
                    {
                        error = ex;
                    }

                    if (fileCopyProgressCallback != null)
                    {
                        fileCopyProgressCallback(filePath, error);
                    }
                }
            }
            if (Recursive)
            {
                List <DirectoryInfo> Directories = GetDirectoryList(SourceInfo.FullName);
                foreach (DirectoryInfo Directory in Directories)
                {
                    CopyDirectory(Directory.FullName, Path.Combine(DestinationInfo.FullName, Directory.Name), Recursive, Options);
                }
            }
        }
Example #14
0
 /// <summary>
 /// Import files in to TheGHOST from a Wii iso
 /// </summary>
 /// <param name="gameFilenames">Lowercase path and filenames seperated by \</param>
 /// <param name="diskFilenames">local disk path and filenames</param>
 void IPluginFileCopy.ImportFiles(string[] gameFilenames, string[] diskFilenames, FileCopyProgress callback)
 {
     extract(gameFilenames, diskFilenames, callback);
 }
Example #15
0
 /// <summary>
 /// Import a single file in to TheGHOST from a Wii ISO
 /// </summary>
 /// <param name="gameFilename">Lowercase path and filename seperated by \</param>
 /// <param name="diskFilename">Local disk path and filename</param>
 void IPluginFileCopy.ImportFile(string gameFilename, string diskFilename, FileCopyProgress callback)
 {
     extract(new string[] { gameFilename }, new string[] { diskFilename }, callback);
 }
Example #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameFiles"></param>
        /// <param name="callback"></param>
        /// <returns>Failed gamefiles.</returns>
        public GameFile[] Import(GameFile[] gameFiles, FileCopyProgress callback)
        {
            List<GameFile> failed = new List<GameFile>();

            _fileCopy.SetSourcePath(_gameLocation);
            _fileCopy.ImportFiles(GameFile.CreateGameArray(gameFiles), GameFile.CreateLocalArray(gameFiles), delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(gameFiles[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });

            foreach (GameFile gf in gameFiles)
            {
                if (!io.File.Exists(gf.LocalName))
                    throw new ApplicationException("Failed to import files from the game source.");

                if (!_files.ContainsKey(gf.GameName))
                {
                    _files.Add(gf.GameName, gf);
                    gf.UpdateLocalDateTime();
                }
            }
            return failed.ToArray();
        }
Example #17
0
        /// <summary>
        /// Imports the notes PAK files for all changed songs
        /// </summary>
        /// <returns>List of failed files</returns>
        public GameFile[] ImportNotesPaks(FileCopyProgress callback)
        {
            List<GameFile> gameSongs = new List<GameFile>();
            List<GameFile> failed = new List<GameFile>();

            string songName;
            foreach (ProjectSong song in _project.ChangedSongs)
            {
                //get notes pak
                songName = _project.GameInfo.GetNotesFilename(song.SongQb.Id);
                if (songName != null)
                    gameSongs.Add(new GameFile(songName, localGameFilename(songName), GameFileType.NotesPak));
            }

            this.Import(gameSongs.ToArray(), delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                {
                    if (!success)
                        failed.Add(gameSongs[fileNo]);
                    if (callback != null)
                        callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                });

            return failed.ToArray();
        }
Example #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameFileType"></param>
        /// <param name="callback"></param>
        /// <param name="gameFilenames"></param>
        /// <returns>Imported gamefiles.</returns>
        public GameFile[] Import(GameFileType gameFileType, FileCopyProgress callback, params string[] gameFilenames)
        {
            List<GameFile> gfs = new List<GameFile>();

            foreach (string s in gameFilenames)
                gfs.Add(new GameFile(s, localGameFilename(s), gameFileType));

            GameFile[] gf = gfs.ToArray();

            Import(gf, callback);
            return gf;
        }
Example #19
0
        private void replace(string[] gameFilenames, string[] diskFilenames, FileCopyProgress callback)
        {
            if (gameFilenames.Length == 0)
                return;

            findMainPartition();

            _gameFiles = gameFilenames;
            _diskFiles = diskFilenames;
            _callback = callback;

            string currPath = Environment.CurrentDirectory;
            Environment.CurrentDirectory = _currPath;
            ReplaceFiles(_isoPath, gameFilenames, diskFilenames, diskFilenames.Length, false, false, _partitionNo, _handle);
            if (Directory.Exists(currPath))
                Environment.CurrentDirectory = currPath;
        }
Example #20
0
        /// <summary>
        /// Imports the notes PAK files for all songs in the EditSongs
        /// </summary>
        /// <returns>Array of extracted GameFiles</returns>
        public GameFile[] ImportBackgroundAudio(FileCopyProgress callback)
        {
            GameFile[] gameSongs = new GameFile[2];
            List<GameFile> failed = new List<GameFile>();

            gameSongs[0] = new GameFile(_project.GameInfo.StreamDat, localGameFilename(_project.GameInfo.StreamDat), GameFileType.Dat);
            gameSongs[1] = new GameFile(_project.GameInfo.StreamWad, localGameFilename(_project.GameInfo.StreamWad), GameFileType.Wad);

            this.Import(gameSongs, delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
            {
                if (!success)
                    failed.Add(gameSongs[fileNo]);
                if (callback != null)
                    callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
            });

            return gameSongs;
        }
Example #21
0
 /// <summary>
 /// Export a single file from TheGHOST to a Wii ISO
 /// </summary>
 /// <param name="diskFilename">Local disk path and filename</param>
 /// <param name="gameFilename">Lowercase path and filename seperated by \</param>
 void IPluginFileCopy.ExportFile(string diskFilename, string gameFilename, FileCopyProgress callback)
 {
     replace(new string[] { gameFilename }, new string[] { diskFilename }, callback);
 }
Example #22
0
        /// <summary>
        /// Imports the QB/PAB/DBG paks
        /// </summary>
        /// <returns>List of failed files</returns>
        public GameFile[] ImportPaks(FileCopyProgress callback)
        {
            List<GameFile> gf = new List<GameFile>();
            GameFile pak = new GameFile(_project.GameInfo.QbPakFilename, localGameFilename(_project.GameInfo.QbPakFilename), GameFileType.QbPak);
            GameFile pab = null;
            List<GameFile> failed = new List<GameFile>();
            if (_project.GameInfo.HasQbPab)
                pab = new GameFile(_project.GameInfo.QbPabFilename, localGameFilename(_project.GameInfo.QbPabFilename), GameFileType.QbPab);
            GameFile dbg = new GameFile(_project.GameInfo.DbgPakFilename, localGameFilename(_project.GameInfo.DbgPakFilename), GameFileType.DbgPak);

            try
            {
                GameFile[] gameSongs;
                if (_project.GameInfo.HasQbPab)
                    gameSongs = GameFile.CreateArray(pak, pab, dbg);
                else
                    gameSongs = GameFile.CreateArray(pak, dbg);

                this.Import(gameSongs, delegate(string gameFilename, string diskFilename, int fileNo, int fileCount, float percentage, bool success)
                    {
                        if (!success)
                            failed.Add(gameSongs[fileNo]);
                        if (callback != null)
                            callback(gameFilename, diskFilename, fileNo, fileCount, percentage, success);
                    });

            }
            finally
            {
            }
            return failed.ToArray();
        }
Example #23
0
        private void extract(string[] gameFilenames, string[] diskFilenames, FileCopyProgress callback)
        {
            if (gameFilenames.Length == 0)
                return;

            findMainPartition();

            FileInfo f;
            foreach (string s in diskFilenames)
            {
                //create all folders
                f = new FileInfo(s);
                if (!Directory.Exists(f.DirectoryName))
                    Directory.CreateDirectory(f.DirectoryName);
                else if (File.Exists(s))
                    FileHelper.Delete(s);
            }

            _gameFiles = gameFilenames;
            _diskFiles = diskFilenames;
            _callback = callback;

            //MessageBox.Show("Current Path: " + Environment.CurrentDirectory);

            string currPath = Environment.CurrentDirectory;
            Environment.CurrentDirectory = _currPath;
            //MessageBox.Show("Path Before Extract: " + Environment.CurrentDirectory);
            ExtractFiles(_isoPath, gameFilenames, diskFilenames, diskFilenames.Length, false, _partitionNo, _handle);
            if (Directory.Exists(currPath))
                Environment.CurrentDirectory = currPath;
            //MessageBox.Show("Path After Extract: " + Environment.CurrentDirectory);
        }