示例#1
0
        private void FileTreeContextAddFile_Click(object sender, EventArgs e)
        {
            Editor.Lib.ShaiyaDataEntry parentEntry = Data.GetFlatEntry(FileTree.SelectedNode.Name);
            if (parentEntry.IsDir == false)
            {
                return;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "All Files *.*|*.*";
            dlg.Multiselect = true;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Editor.Lib.ShaiyaDataEntry newEntry;
            for (int i = 0; i < dlg.FileNames.Length; i++)
            {
                if (Data.AddFile(parentEntry, dlg.FileNames[i], out newEntry) == false)
                {
                    MessageBox.Show("Fehler beim hinzufügen der Datei!\n" + dlg.FileNames[i]);
                    continue;
                }

                int index = GetImageIndex(newEntry.Filename);
                FileTree.SelectedNode.Nodes.Add(newEntry.ID, newEntry.Filename, index, index);
            }
        }
示例#2
0
        private void FileTreeContextReplace_Click(object sender, EventArgs e)
        {
            Editor.Lib.ShaiyaDataEntry entry = Data.GetFlatEntry(FileTree.SelectedNode.Name);
            if (entry.IsDir == true)
            {
                return;
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = entry.Filename + "|" + entry.Filename;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (Data.UpdateFile(entry.ID, dlg.FileName) == false)
            {
                MessageBox.Show("Fehler beim ersetzen der Datei!?");
                return;
            }

            // reload Content
            //LoadData( Data.BasePath + ".sah" );
        }
示例#3
0
        private void FileTreeContext_Opening(object sender, CancelEventArgs e)
        {
            if (FileTree.Nodes.Count == 0 || FileTree.SelectedNode == null)
            {
                e.Cancel = true;
                return;
            }

            // allowed to add in a dir?
            if (FileTree.SelectedNode != FileTree.Nodes[0])
            {
                // not root, is it a dir?
                Editor.Lib.ShaiyaDataEntry entry = Data.GetFlatEntry(FileTree.SelectedNode.Name);
                if (entry.IsDir == false)
                {
                    // its a file, not allowed to add here
                    FileTreeContextSep1.Visible      = false;
                    FileTreeContextAddFile.Visible   = false;
                    FileTreeContextAddFolder.Visible = false;
                    // allowed to replace
                    FileTreeContextReplace.Enabled = true;
                    return;
                }
            }

            // its a dir, allowed to add files/dirs
            FileTreeContextSep1.Visible      = true;
            FileTreeContextAddFile.Visible   = true;
            FileTreeContextAddFolder.Visible = true;
            // not allowed to replace
            FileTreeContextReplace.Enabled = false;
        }
示例#4
0
        private void Extract(string FlatName, string RootDir)
        {
            try {
                Editor.Lib.ShaiyaDataEntry entry = mData.GetFlatEntry(FlatName);
                if (entry == null)
                {
                    return;
                }

                if (entry.IsDir == true)
                {
                    for (int i = 0; i < entry.Entrys.Count; i++)
                    {
                        Extract(entry.Entrys[i].ID, RootDir);
                    }
                    return;
                }

                byte[] buffer;
                mData.GetData(entry, out buffer);


                string dataDir   = mData.GetRootDir(entry);
                string saveInDir = Path.Combine(RootDir, dataDir) + @"\" + entry.Filename;
                Directory.CreateDirectory(Path.GetDirectoryName(saveInDir));
                File.WriteAllBytes(saveInDir, buffer);

                mWorker.ReportProgress(0);

                entry  = null;
                buffer = null;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
示例#5
0
        private void PreviewTextFile(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
        {
            PanelPreview.Controls.Clear();
            RichTextBox box = new RichTextBox();

            box.Dock     = System.Windows.Forms.DockStyle.Fill;
            box.Location = System.Drawing.Point.Empty;
            box.Name     = "box";
            box.ReadOnly = true;
            box.Text     = "";

            box.Text = System.Text.Encoding.Unicode.GetString(buffer);
            PanelPreview.Controls.Add(box);
        }
示例#6
0
        private void DoPreview(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
        {
            if (buffer == null || Entry == null)
            {
                PanelPreview.Controls.Clear();
                return;
            }

            switch (Path.GetExtension(Entry.Filename).ToLower())
            {
            case ".txt":
                PreviewTextFile(buffer, Entry);
                return;

            case ".tga":
                PreviewImageTgaFile(buffer, Entry);
                return;

            case ".dds":
                try {
                    PreviewImageDdsFile(buffer, Entry);
                } catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);
                }
                return;

            case ".jpg":
            case ".jepg":
            case ".bmp":
                PreviewImageFile(buffer, Entry);
                return;

            case ".wav":
            case ".mp3":
            case ".mp4":
                PreviewSoundFile(buffer, Entry);
                return;

            case ".sdata":
                PreviewSDataFile(buffer, Entry);
                return;
            }
        }
示例#7
0
 private void PreviewSDataFile(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
 {
     /*byte[] decompressedBuf;
      * byte[] compressedBuf;
      * string basePath = AppDomain.CurrentDomain.BaseDirectory;
      * for( int i = 0; i < 100; i++ ) {
      *      compressedBuf = new byte[ buffer.Length - i ];
      *      Buffer.BlockCopy( buffer, i, compressedBuf, 0, compressedBuf.Length );
      *      try {
      *              System.Diagnostics.Debug.Write( "try " + i + "..." );
      *              decompressedBuf = Editor.Lib.Deflate.Decompress( compressedBuf );
      *              System.Diagnostics.Debug.WriteLine( " success! " + decompressedBuf.Length + " bytes" );
      *
      *              File.WriteAllBytes( AppDomain.CurrentDomain.BaseDirectory + "debug_" + i + ".txt", decompressedBuf );
      *      } catch( Exception e ) {
      *              //System.Diagnostics.Debug.WriteLine( e );
      *              System.Diagnostics.Debug.WriteLine( " fail.." );
      *      }
      * }*/
 }
示例#8
0
        private void PreviewImageTgaFile(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
        {
            PanelPreview.Controls.Clear();
            PictureBox box = new PictureBox();

            box.Dock     = System.Windows.Forms.DockStyle.Fill;
            box.Location = System.Drawing.Point.Empty;
            box.Name     = "box";


            try {
                using (MemoryStream tmpStream = new MemoryStream(buffer)) {
                    box.Image = new TargaImage(tmpStream).Image;
                }
            } catch {
                box.Image = null;
                MessageBox.Show("unable to Preview this Image :/");
            }
            PanelPreview.Controls.Add(box);
        }
示例#9
0
        private void PreviewImageDdsFile(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
        {
            PanelPreview.Controls.Clear();
            PictureBox box = new PictureBox();

            box.Dock     = System.Windows.Forms.DockStyle.Fill;
            box.Location = System.Drawing.Point.Empty;
            box.Name     = "box";

            string tmpFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()) + ".dds";

            try {
                File.WriteAllBytes(tmpFile, buffer);
                box.Image = DevIL.DevIL.LoadBitmap(tmpFile);
            } catch {
                box.Image = null;
                MessageBox.Show("unable to Preview this Image :/");
            } finally {
                File.Delete(tmpFile);
            }
            PanelPreview.Controls.Add(box);
        }
示例#10
0
        private void FileTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;

            if (node == FileTree.Nodes[0])                // root
            {
                return;
            }

            Editor.Lib.ShaiyaDataEntry entry = Data.GetFlatEntry(node.Name);
            if (entry == null)
            {
                MessageBox.Show("Failed to fetch Entry from File ôo");
            }
            if (entry.IsDir == true)
            {
                return;
            }

            byte[] buffer;
            Data.GetData(entry, out buffer);
            DoPreview(buffer, entry);
        }
示例#11
0
 private void PreviewSoundFile(byte[] buffer, Editor.Lib.ShaiyaDataEntry Entry)
 {
     Editor.Lib.Native.PlaySound(ref buffer[0], IntPtr.Zero, 5);
 }