Beispiel #1
0
        private void Finish()
        {
            if (listBox_Textures.SelectedIndex != -1)
            {
                SelectedTexture = listBox_Textures.SelectedItem as EmbEntry;
            }

            Close();
        }
Beispiel #2
0
 public TextureSelector(EMB_File _embFile, Window parent, EmbEntry initialSelection)
 {
     embFile = _embFile;
     InitializeComponent();
     DataContext = this;
     Owner       = parent;
     listBox_Textures.SelectedItem = initialSelection;
     listBox_Textures.ScrollIntoView(initialSelection);
 }
        public RecolorTexture_HueSet(EmbEntry _texture, Window parent)
        {
            CurrentTexture = _texture;
            InitializeComponent();
            DataContext = this;
            Owner       = parent;

            OriginalTextureBackup = CurrentTexture.DdsImage;
            stopwatch.Start();
        }
Beispiel #4
0
        private void RenameFile_PopUp(EmbEntry embEntry)
        {
            RenameForm renameForm = new RenameForm(System.IO.Path.GetFileNameWithoutExtension(embEntry.Name), ".dds", String.Format("Renaming {0}", embEntry.Name), EmbFile, this, RenameForm.Mode.Texture);

            renameForm.ShowDialog();

            if (renameForm.WasNameChanged)
            {
                embEntry.Name = renameForm.NameValue + ".dds";
            }
        }
        private void RenameFile_PopUp(EmbEntry embEntry)
        {
            RenameForm renameForm = new RenameForm(System.IO.Path.GetFileNameWithoutExtension(embEntry.Name), ".dds", String.Format("Renaming {0}", embEntry.Name), EmbFile, this, RenameForm.Mode.Texture);

            renameForm.ShowDialog();

            if (renameForm.WasNameChanged)
            {
                UndoManager.Instance.AddUndo(new UndoableProperty <EmbEntry>(nameof(EmbEntry.Name), embEntry, embEntry.Name, renameForm.NameValue + ".dds", "EMB Rename"));
                embEntry.Name = renameForm.NameValue + ".dds";
            }
        }
Beispiel #6
0
        private void Uninstall_EMB(string path, _File file)
        {
            try
            {
                EMB_File binaryFile = (EMB_File)GetParsedFile <EMB_File>(path, false);
                EMB_File cpkBinFile = (EMB_File)GetParsedFile <EMB_File>(path, true);

                Section section = file.GetSection(Sections.EMB_Entry);

                if (section != null)
                {
                    for (int i = 0; i < section.IDs.Count; i++)
                    {
                        int idNum;

                        if (int.TryParse(section.IDs[i], out idNum))
                        {
                            //ID is number (index)
                            EmbEntry original = (cpkBinFile != null) ? cpkBinFile.GetEntry(idNum) : null;
                            binaryFile.RemoveEntry(section.IDs[i], original);
                        }
                        else
                        {
                            //ID is string (name)
                            EmbEntry original      = (cpkBinFile != null) ? cpkBinFile.GetEntry(section.IDs[i]) : null;
                            var      existingEntry = binaryFile.Entry.FirstOrDefault(x => x.Name == section.IDs[i]);

                            if (existingEntry != null)
                            {
                                binaryFile.RemoveEntry(binaryFile.Entry.IndexOf(existingEntry).ToString(), original);
                            }
                        }
                    }

                    binaryFile.TrimNullEntries();
                }
            }
            catch (Exception ex)
            {
                string error = string.Format("Failed at {0} uninstall phase ({1}).", ErrorCode.EMB, path);
                throw new Exception(error, ex);
            }
        }
        //EMB Options
        private void EmbOptions_AddTexture_Click(object sender, RoutedEventArgs e)
        {
            List <IUndoRedo> undos = new List <IUndoRedo>();

            //Validation
            if (EmbFile.Entry.Count >= EMB_File.MAX_EFFECT_TEXTURES)
            {
                MessageBox.Show(String.Format("The maximum allowed amount of textures has been reached. Cannot add anymore.", EMB_File.MAX_EFFECT_TEXTURES), "Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                return;
            }

            //Add file
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Title       = "Add texture(s)...";
            openFile.Filter      = "DDS texture files | *.dds";
            openFile.Multiselect = true;
            openFile.ShowDialog(this);

            int renameCount = 0;
            int added       = 0;

            foreach (var file in openFile.FileNames)
            {
                if (File.Exists(file) && !String.IsNullOrWhiteSpace(file))
                {
                    if (System.IO.Path.GetExtension(file) != ".dds")
                    {
                        MessageBox.Show(String.Format("{0} is not a supported format.", System.IO.Path.GetExtension(file)), "Invalid Format", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    byte[] bytes    = File.ReadAllBytes(file);
                    string fileName = System.IO.Path.GetFileName(file);

                    EmbEntry newEntry = new EmbEntry();
                    newEntry.Data = bytes.ToList();
                    newEntry.Name = EmbFile.GetUnusedName(fileName);
                    newEntry.LoadDds();


                    //Validat the emb again, so we dont go over the limit
                    if (EmbFile.Entry.Count >= EMB_File.MAX_EFFECT_TEXTURES && IsForContainer)
                    {
                        MessageBox.Show(String.Format("The maximum allowed amount of textures has been reached. Cannot add anymore.\n\n{1} of the selected textures were added before the limit was reached.", EMB_File.MAX_EFFECT_TEXTURES, added), "Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                        return;
                    }

                    //Add the emb
                    undos.Add(new UndoableListAdd <EmbEntry>(EmbFile.Entry, newEntry));
                    EmbFile.Entry.Add(newEntry);
                    added++;

                    if (newEntry.Name != fileName)
                    {
                        renameCount++;
                    }
                }
            }

            undos.Add(new UndoActionDelegate(this, nameof(RefreshTextureCount), true));
            RefreshTextureCount();

            if (added > 0)
            {
                UndoManager.Instance.AddUndo(new CompositeUndo(undos, added > 1 ? "Add Textures" : "Add Texture"));
            }

            if (renameCount > 0)
            {
                MessageBox.Show(String.Format("{0} texture(s) were renamed during the add process because textures already existed in the EMB with the same name.", renameCount), "Add Texture", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }