Skip to content

Commit c847d40

Browse files
committed
RARC : Add rewritten code ported from reborn project
1 parent ed01567 commit c847d40

File tree

4 files changed

+232
-307
lines changed

4 files changed

+232
-307
lines changed

File_Format_Library.zip

11.3 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Toolbox;
7+
using System.Windows.Forms;
8+
using System.IO;
9+
using Toolbox.Library.Forms;
10+
using Toolbox.Library;
11+
using Toolbox.Library.IO;
12+
13+
namespace FirstPlugin
14+
{
15+
public class RARC : IArchiveFile, IFileFormat, IContextMenuNode
16+
{
17+
public FileType FileType { get; set; } = FileType.Archive;
18+
19+
public bool CanSave { get; set; }
20+
public string[] Description { get; set; } = new string[] { "RARC" };
21+
public string[] Extension { get; set; } = new string[] { "*.rarc", "*.arc", "*.crar", "*.yaz0" };
22+
public string FileName { get; set; }
23+
public string FilePath { get; set; }
24+
public IFileInfo IFileInfo { get; set; }
25+
26+
public bool CanAddFiles { get; set; }
27+
public bool CanRenameFiles { get; set; } = true;
28+
public bool CanReplaceFiles { get; set; }
29+
public bool CanDeleteFiles { get; set; }
30+
31+
public bool Identify(System.IO.Stream stream)
32+
{
33+
using (var reader = new Toolbox.Library.IO.FileReader(stream, true))
34+
{
35+
return reader.CheckSignature(4, "RARC") || reader.CheckSignature(4, "CRAR");
36+
}
37+
}
38+
39+
public Type[] Types
40+
{
41+
get
42+
{
43+
List<Type> types = new List<Type>();
44+
return types.ToArray();
45+
}
46+
}
47+
48+
RARC_Parser RarcFileData;
49+
50+
public IEnumerable<ArchiveFileInfo> Files => RarcFileData.Files;
51+
52+
public void ClearFiles() { RarcFileData.Files.Clear(); }
53+
54+
public ToolStripItem[] GetContextMenuItems()
55+
{
56+
List<ToolStripItem> Items = new List<ToolStripItem>();
57+
Items.Add(new ToolStripMenuItem("Save", null, SaveAction, Keys.Control | Keys.S));
58+
Items.Add(new ToolStripMenuItem("Batch Rename Galaxy (Mario Galaxy)", null, BatchRenameGalaxy, Keys.Control | Keys.S));
59+
return Items.ToArray();
60+
}
61+
62+
private void BatchRenameGalaxy(object sender, EventArgs args)
63+
{
64+
string ActorName = Path.GetFileNameWithoutExtension(FileName);
65+
66+
RenameDialog dialog = new RenameDialog();
67+
dialog.SetString(ActorName);
68+
69+
if (dialog.ShowDialog() == DialogResult.OK)
70+
{
71+
string NewActorName = dialog.textBox1.Text;
72+
FileName = NewActorName + ".arc";
73+
74+
foreach (var file in RarcFileData.Files)
75+
{
76+
file.FileName = file.FileName.Replace(ActorName, NewActorName);
77+
file.UpdateWrapper();
78+
}
79+
}
80+
}
81+
82+
private void SaveAction(object sender, EventArgs args)
83+
{
84+
SaveFileDialog sfd = new SaveFileDialog();
85+
sfd.Filter = Utils.GetAllFilters(this);
86+
sfd.FileName = FileName;
87+
88+
if (sfd.ShowDialog() == DialogResult.OK)
89+
{
90+
STFileSaver.SaveFileFormat(this, sfd.FileName);
91+
}
92+
}
93+
94+
public bool IsLittleEndian { get; set; } = false;
95+
96+
public void Load(System.IO.Stream stream)
97+
{
98+
CanSave = true;
99+
CanRenameFiles = true;
100+
CanReplaceFiles = true;
101+
102+
RarcFileData= new RARC_Parser(stream);
103+
}
104+
105+
public void Save(System.IO.Stream stream)
106+
{
107+
RarcFileData.Save(stream);
108+
}
109+
110+
public void Unload() { }
111+
112+
public bool AddFile(ArchiveFileInfo archiveFileInfo)
113+
{
114+
return false;
115+
}
116+
117+
public bool DeleteFile(ArchiveFileInfo archiveFileInfo)
118+
{
119+
return false;
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)