Пример #1
0
        private static void PackXBox360(string sourcePath, string saveFileName, Platform platform, bool updateSng, bool updateManifest)
        {
            if (updateSng && platform.version == GameVersion.RS2014)
            {
                UpdateSng2014(sourcePath, platform);
                UpdateManifest2014(sourcePath, platform);
            }

            var songData    = new DLCPackageData();
            var packageRoot = Path.Combine(sourcePath, ROOT_XBox360);

            // If 'Root' directory doesn't exist the packing is a conversion process from another platform
            if (!Directory.Exists(packageRoot))
            {
                var songXmlFiles = Directory.EnumerateFiles(sourcePath, "*_*.xml", SearchOption.AllDirectories);

                var songTitle = String.Empty;
                foreach (var xml in songXmlFiles)
                {
                    if (Path.GetFileNameWithoutExtension(xml).ToLower().Contains("vocal") || Path.GetFileNameWithoutExtension(xml).ToLower().Contains("showlight"))
                    {
                        continue;
                    }

                    var song = Song2014.LoadFromFile(xml);

                    songData.SongInfo = new SongInfo();
                    songData.SongInfo.SongDisplayName = songTitle = song.Title;
                    songData.SongInfo.Artist          = song.ArtistName;

                    songData.SignatureType = PackageMagic.CON;
                    break;
                }

                var directoryList = Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories);
                var fileList      = Directory.EnumerateFiles(sourcePath, "*.*", SearchOption.AllDirectories);

                // MAKE THE XBOX360 EXPECTED STRUCTURE TO PACK WORK
                var newPackageName = songTitle.GetValidSongName(songTitle).ToLower();
                var newSongDir     = Path.Combine(packageRoot, newPackageName);

                // Creating new directories
                Directory.CreateDirectory(packageRoot);
                Directory.CreateDirectory(newSongDir);

                // Create PackageList file
                var packListFile = Path.Combine(packageRoot, "PackageList.txt");
                File.WriteAllText(packListFile, newPackageName);

                // Move directories to new path
                foreach (string dir in directoryList)
                {
                    Directory.CreateDirectory(dir.Replace(sourcePath, newSongDir));
                }

                // Move files to new path
                foreach (string file in fileList)
                {
                    File.Move(file, file.Replace(sourcePath, newSongDir));
                }

                // Delete old empty directories
                foreach (string emptyDir in directoryList)
                {
                    DirectoryExtension.SafeDelete(emptyDir);
                }
            }

            foreach (var directory in Directory.EnumerateDirectories(packageRoot))
            {
                PackInnerXBox360(packageRoot, directory);
            }

            IEnumerable <string> xboxHeaderFiles = Directory.EnumerateFiles(sourcePath, "*.txt", SearchOption.TopDirectoryOnly);

            if (xboxHeaderFiles.Count() == 1)
            {
                foreach (var file in xboxHeaderFiles)
                {
                    try
                    {
                        string[] xboxHeader = File.ReadAllLines(file);
                        if (xboxHeader != null && xboxHeader.Length > 73)
                        {
                            if (xboxHeader[0].IndexOf("LIVE") > 0)
                            {
                                songData.SignatureType = PackageMagic.LIVE;

                                for (int i = 2; i <= 48; i = i + 3)
                                {
                                    long id   = Convert.ToInt64(xboxHeader[i].GetHeaderValue(), 16);
                                    int  bit  = Convert.ToInt32(xboxHeader[i + 1].GetHeaderValue());
                                    int  flag = Convert.ToInt32(xboxHeader[i + 2].GetHeaderValue());

                                    if (id != 0)
                                    {
                                        songData.XBox360Licenses.Add(new XBox360License()
                                        {
                                            ID = id, Bit = bit, Flag = flag
                                        });
                                    }
                                }
                            }

                            string songInfo = xboxHeader[74];

                            int    index      = songInfo.IndexOf(" by ");
                            string songTitle  = (index > 0) ? songInfo.Substring(0, index) : songInfo;
                            string songArtist = (index > 4) ? songInfo.Substring(index + 4) : songInfo;

                            if (!String.IsNullOrEmpty(songInfo))
                            {
                                songData.SongInfo = new SongInfo();
                                songData.SongInfo.SongDisplayName = songInfo;
                                songData.SongInfo.Artist          = songInfo;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException("XBox360 header file (.txt) not found or is invalid. " + Environment.NewLine +
                                                       "The file is in the same level at 'Root' folder along with the files: 'Content image.png' and 'Package image.png' and no other file .txt can be here.", ex);
                    }
                }
            }

            IEnumerable <string> xboxFiles = Directory.EnumerateFiles(packageRoot);

            DLCPackageCreator.BuildXBox360Package(saveFileName, songData, xboxFiles, platform.version);

            foreach (var file in xboxFiles)
            {
                if (Path.GetExtension(file) == ".psarc" && File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }