Exemplo n.º 1
0
        public SongINIWindow(KFN KFN)
        {
            InitializeComponent();

            this.KFN = KFN;

            GridView blocksGrid = new GridView
            {
                ColumnHeaderContainerStyle =
                    System.Windows.Application.Current.Resources["GridViewColumnHeaderStyle"] as Style
            };

            blocksGrid.Columns.Add(new GridViewColumn()
            {
                Header = "Name",
                Width  = 80,
                DisplayMemberBinding = new System.Windows.Data.Binding("Name")
            });
            blocksGrid.Columns.Add(new GridViewColumn()
            {
                Header = "Content ID",
                Width  = 80,
                DisplayMemberBinding = new System.Windows.Data.Binding("Id")
            });
            blocksGrid.Columns.Add(new GridViewColumn()
            {
                Header = "Content type",
                DisplayMemberBinding = new System.Windows.Data.Binding("Type")
            });
            iniBlocksView.View = blocksGrid;

            this.ParseINI(KFN);
        }
Exemplo n.º 2
0
        private void OpenKFNMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (OpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                viewConfigButton.IsEnabled = false;
                KFN = new KFN(OpenFileDialog.FileName);
                if (KFN.isError != null)
                {
                    System.Windows.MessageBox.Show(KFN.isError);
                    return;
                }
                MainWindowElement.Title = this.windowTitle + " - " + KFN.FullFileName;
                this.UpdateKFN();
                viewConfigButton.IsEnabled = true;
                toEMZMenu.IsEnabled        = true;
                toMP3LRCMenu.IsEnabled     = true;
                toKFNMenu.IsEnabled        = true;

                KFN.ResourceFile encResource = KFN.Resources.Where(r => r.IsEncrypted == true).FirstOrDefault();
                if (encResource != null)
                {
                    decryptKFN.IsEnabled = true;
                }
            }
        }
Exemplo n.º 3
0
        private void ParseINI(KFN KFN)
        {
            KFN.ResourceFile resource = KFN.Resources.Where(r => r.FileName == "Song.ini").First();
            byte[]           data     = KFN.GetDataFromResource(resource);
            string           iniText  = new string(Encoding.UTF8.GetChars(data));

            SongINI sINI = new SongINI(iniText);

            iniBlocksView.ItemsSource = sINI.Blocks;
            this.AutoSizeColumns(iniBlocksView.View as GridView);
        }
Exemplo n.º 4
0
 private void ToKFNMenu_Click(object sender, RoutedEventArgs e)
 {
     KFN.ChangeKFN(KFN.Resources.Where(r => r.IsExported == true).ToList(), (bool)decryptKFN.IsChecked);
     System.Windows.MessageBox.Show("Done!");
     KFN = new KFN(KFN.FullFileName);
     if (KFN.isError != null)
     {
         System.Windows.MessageBox.Show(KFN.isError);
         return;
     }
     this.UpdateKFN();
 }
Exemplo n.º 5
0
        static KFN ReadFile(string filePath)
        {
            if (!Regex.IsMatch(filePath, @"[\/]"))
            {
                filePath = Directory.GetCurrentDirectory() + "\\" + filePath;
            }
            if (!File.Exists(filePath))
            {
                // error
                return(null);
            }
            KFN fileData = new KFN(filePath);

            if (fileData == null)
            {
                // error
                return(null);
            }
            return(fileData);
        }
Exemplo n.º 6
0
        public ExportWindow(string exportType, KFN KFN)
        {
            InitializeComponent();

            WindowElement.Title += exportType;
            this.KFN             = KFN;
            this.exportType      = exportType;

            videoLabel.Visibility      = (exportType == "EMZ") ? Visibility.Visible : Visibility.Hidden;
            videoSelect.Visibility     = (exportType == "EMZ") ? Visibility.Visible : Visibility.Hidden;
            playVideoButton.Visibility = (exportType == "EMZ") ? Visibility.Visible : Visibility.Hidden;
            deleteID3Tags.IsChecked    = true;
            deleteID3Tags.Visibility   = (exportType == "MP3+LRC") ? Visibility.Visible : Visibility.Hidden;
            artistLabel.Visibility     = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;
            titleLabel.Visibility      = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;
            artistSelect.Visibility    = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;
            titleSelect.Visibility     = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;
            encLabel.Visibility        = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;
            encSelect.Visibility       = (exportType != "EMZ") ? Visibility.Visible : Visibility.Hidden;

            // TODO
            playVideoButton.IsEnabled = false;
            playAudioButton.IsEnabled = false;

            // AUDIO
            List <KFN.ResourceFile> audios = KFN.Resources.Where(r => r.FileType == "Audio").ToList();
            string audioSource             = KFN.GetAudioSourceName();

            audioSelect.ItemsSource       = audios;
            audioSelect.DisplayMemberPath = "FileName";
            audioSelect.SelectedItem      = audios.Where(a => a.FileName == audioSource).FirstOrDefault();
            if (audioSelect.SelectedItem == null)
            {
                System.Windows.MessageBox.Show("Can`t find audio source!");
                return;
            }
            if (audios.Count == 1)
            {
                audioSelect.IsEnabled = false;
            }

            // LYRICS
            Dictionary <string, string> lyrics = new Dictionary <string, string>();
            List <KFN.ResourceFile>     texts  = KFN.Resources.Where(r => r.FileType == "Text").ToList();

            foreach (KFN.ResourceFile resource in texts)
            {
                lyrics.Add(resource.FileName, this.GetResourceText(resource));
            }

            KFN.ResourceFile songIni = KFN.Resources.Where(r => r.FileName == "Song.ini").First();
            byte[]           data    = KFN.GetDataFromResource(songIni);
            string           iniText = new string(Encoding.UTF8.GetChars(data));
            SongINI          sINI    = new SongINI(iniText);

            foreach (SongINI.BlockInfo block in sINI.Blocks.Where(b => b.Id == "1" || b.Id == "2"))
            {
                string lyricFromBlock = (exportType == "EMZ")
                    ? KFN.INIToELYR(block.Content)
                    : KFN.INIToExtLRC(block.Content);
                if (lyricFromBlock != null)
                {
                    lyrics.Add("Song.ini: " + block.Name, lyricFromBlock);
                }
                else
                {
                    lyrics.Add("Song.ini: " + block.Name, "Can`t convert lyric from Song.ini");
                }
            }
            lyricSelect.DisplayMemberPath = "Key";
            lyricSelect.SelectedIndex     = 0;
            if (lyrics.Count == 1)
            {
                lyricSelect.IsEnabled = false;
            }
            lyricSelect.ItemsSource = lyrics;
            lyricPreview.Text       = ((KeyValuePair <string, string>)lyricSelect.SelectedItem).Value;

            // ARTIST-TITLE
            if (exportType == "MP3+LRC")
            {
                List <string> artists = new List <string> {
                    null
                };
                List <string> titles = new List <string> {
                    null
                };

                KeyValuePair <string, string> kfnArtist = KFN.Properties.Where(p => p.Key == "Artist").FirstOrDefault();
                if (kfnArtist.Value != null && kfnArtist.Value.Length > 0)
                {
                    artists.Add(kfnArtist.Value);
                }
                KeyValuePair <string, string> kfnTitle = KFN.Properties.Where(p => p.Key == "Title").FirstOrDefault();
                if (kfnTitle.Value != null && kfnTitle.Value.Length > 0)
                {
                    titles.Add(kfnTitle.Value);
                }

                foreach (KFN.ResourceFile resource in KFN.Resources.Where(r => r.FileType == "Audio"))
                {
                    string[] atFromID3 = ID3Class.GetArtistAndTitle(KFN.GetDataFromResource(resource));
                    if (atFromID3[0] != null)
                    {
                        artists.Add(atFromID3[0]);
                    }
                    if (atFromID3[1] != null)
                    {
                        titles.Add(atFromID3[1]);
                    }
                }
                artists = artists.Distinct().ToList();
                titles  = titles.Distinct().ToList();

                artistSelect.ItemsSource   = artists;
                artistSelect.SelectedIndex = 0;
                titleSelect.ItemsSource    = titles;
                titleSelect.SelectedIndex  = 0;

                encSelect.ItemsSource       = this.encodings;
                encSelect.DisplayMemberPath = "Value";
                encSelect.SelectedIndex     = 0;
            }

            // VIDEO
            if (exportType == "EMZ")
            {
                List <KFN.ResourceFile> videos = KFN.Resources.Where(r => r.FileType == "Video").ToList();
                if (videos.Count == 0)
                {
                    videos.Add(new KFN.ResourceFile("Video", "video not found", 0, 0, 0, false));
                    videoSelect.IsEnabled = false;
                }
                else
                {
                    videos.Add(new KFN.ResourceFile("Video", "don`t use video", 0, 0, 0, false));
                }
                videoSelect.ItemsSource       = videos;
                videoSelect.DisplayMemberPath = "FileName";
                videoSelect.SelectedIndex     = 0;
            }
        }
Exemplo n.º 7
0
    public void ChangeKFN(List <ResourceFile> resources, bool needDecrypt = false)
    {
        this.error = null;

        string sourceKFNFile = this.fullFileName + ".bak";

        File.Copy(this.fullFileName, sourceKFNFile);

        byte[] sourcePropHeader = new byte[this.endOfPropsOffset];
        using (FileStream fs = new FileStream(sourceKFNFile, FileMode.Open, FileAccess.ReadWrite))
        {
            fs.Read(sourcePropHeader, 0, sourcePropHeader.Length);
        }

        File.Delete(this.fullFileName);
        using (FileStream newFile = new FileStream(this.fullFileName, FileMode.Create, FileAccess.ReadWrite))
        {
            newFile.Write(sourcePropHeader, 0, sourcePropHeader.Length);

            if (needDecrypt)
            {
                newFile.Position = 4;

                byte[] prop      = new byte[5];
                byte[] propValue = new byte[4];
                int    maxProps  = 40;
                while (maxProps > 0)
                {
                    newFile.Read(prop, 0, prop.Length);
                    string propName = new string(Encoding.UTF8.GetChars(new ArraySegment <byte>(prop, 0, 4).ToArray()));
                    if (propName == "ENDH")
                    {
                        newFile.Position += 4;
                        break;
                    }
                    else if (propName == "FLID")
                    {
                        newFile.Read(propValue, 0, propValue.Length);
                        uint   valueLength = BitConverter.ToUInt32(propValue, 0);
                        byte[] zeroValue   = new byte[valueLength];
                        newFile.Write(zeroValue, 0, zeroValue.Length);

                        maxProps--;
                        continue;
                    }
                    else if (propName == "RGHT")
                    {
                        byte[] zeroValue = new byte[4];
                        newFile.Write(zeroValue, 0, zeroValue.Length);

                        maxProps--;
                        continue;
                    }
                    if (prop[4] == 1)
                    {
                        newFile.Position += 4;
                    }
                    else if (prop[4] == 2)
                    {
                        newFile.Read(propValue, 0, propValue.Length);
                        newFile.Position += BitConverter.ToInt32(propValue, 0);
                    }
                    maxProps--;
                }
            }

            byte[] numOfResources = BitConverter.GetBytes(resources.Count);
            newFile.Write(numOfResources, 0, numOfResources.Length);
            int nOffset = 0;
            foreach (ResourceFile resource in resources.OrderBy(r => r.FileOffset))
            {
                byte[] resourceNameLenght      = BitConverter.GetBytes(resource.FileName.Length);
                byte[] resourceLenght          = BitConverter.GetBytes(resource.FileLength);
                byte[] resourceEncryptedLenght = (needDecrypt)
                    ? resourceLenght
                    : BitConverter.GetBytes(resource.EncLength);
                int    encrypted         = (resource.IsEncrypted) ? 1 : 0;
                byte[] resourceEncrypted = (needDecrypt)
                    ? new byte[4]
                    : BitConverter.GetBytes(encrypted);

                newFile.Write(resourceNameLenght, 0, resourceNameLenght.Length);
                byte[] resourceName = Encoding.GetEncoding(this.resourceNamesEncodingAuto).GetBytes(resource.FileName);
                newFile.Write(resourceName, 0, resourceName.Length);
                byte[] type = BitConverter.GetBytes(this.GetFileTypeId(resource.FileType));
                newFile.Write(type, 0, type.Length);
                newFile.Write(resourceLenght, 0, resourceLenght.Length);
                byte[] rOffset = BitConverter.GetBytes(nOffset);
                newFile.Write(rOffset, 0, rOffset.Length);
                nOffset += (needDecrypt) ? resource.FileLength : resource.EncLength;
                newFile.Write(resourceEncryptedLenght, 0, resourceEncryptedLenght.Length);
                newFile.Write(resourceEncrypted, 0, resourceEncrypted.Length);
            }

            KFN sourceKFN = new KFN(sourceKFNFile);
            foreach (ResourceFile resource in resources.OrderBy(r => r.FileOffset))
            {
                byte[] rData = sourceKFN.GetDataFromResource(resource, needDecrypt);
                newFile.Write(rData, 0, rData.Length);
            }
        }
    }