Skip to content

Commit 4462f1e

Browse files
committed
Update library to better accomodate a more organised read/write layout
1 parent 4e67c16 commit 4462f1e

66 files changed

Lines changed: 1362 additions & 1547 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vs/OMI Filetype Library/v16/.suo

7 KB
Binary file not shown.

.vs/OMI Filetype Library/v17/.suo

141 KB
Binary file not shown.

OMI Filetype Library/CSMtoCSMB.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using OMI_Filetypes.Classes.Formats;
7+
using OMI_Filetypes.Classes.Workers.CSMBinaryWorker;
8+
9+
namespace OMI_Filetype_Library
10+
{
11+
internal class CSMtoCSMB
12+
{
13+
14+
15+
//Part Name
16+
//Part Parent(HEAD, BODY, LEG0, LEG1, ARM0, ARM1)
17+
//Part Name
18+
//Position-X
19+
//Position-Y
20+
//Position-Z
21+
//Size-X
22+
//Size-Y
23+
//Size-Z
24+
//UV-Y
25+
//UV-X
26+
27+
public List<string> CSMBlock = new List<string>();
28+
29+
public CSMBFile TryParse(string CSM)
30+
{
31+
CSMBFile NewFile = new CSMBFile();
32+
int y = 0;
33+
int i = 0;
34+
string[] CSMLines = CSM.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
35+
foreach (string line in CSMLines)
36+
{
37+
if (i > 10)
38+
{
39+
GetModelPartFromCSM(CSMBlock, NewFile, y);
40+
CSMBlock.Clear();
41+
i = 0;
42+
y++;
43+
}
44+
CSMBlock.Add(line + "\n");
45+
i++;
46+
}
47+
48+
return NewFile;
49+
}
50+
51+
public void GetModelPartFromCSM(List<string> CSM, CSMBFile csmb, int Instance)
52+
{
53+
Random rnd = new Random();
54+
CSMBFile.CSMPart part = new CSMBFile.CSMPart();
55+
string PartName = CSM[0].Replace("\n","");
56+
Console.WriteLine(PartName+Instance);
57+
string PartParent = CSM[1];
58+
switch (PartParent)
59+
{
60+
case "HEAD":
61+
part.Parent = CSMBFile.PartParent.HEAD;
62+
break;
63+
case "BODY":
64+
part.Parent = CSMBFile.PartParent.BODY;
65+
break;
66+
case "ARM0":
67+
part.Parent = CSMBFile.PartParent.ARM0;
68+
break;
69+
case "ARM1":
70+
part.Parent = CSMBFile.PartParent.ARM1;
71+
break;
72+
case "LEG0":
73+
part.Parent = CSMBFile.PartParent.LEG0;
74+
break;
75+
case "LEG1":
76+
part.Parent = CSMBFile.PartParent.LEG1;
77+
break;
78+
}
79+
try
80+
{
81+
part.Position[0] = float.Parse(CSM[3]);
82+
}
83+
catch
84+
{
85+
part.Position[0] = 0.0f;
86+
}
87+
part.Position[1] = float.Parse(CSM[4]);
88+
part.Position[2] = float.Parse(CSM[5]);
89+
part.Size[0] = float.Parse(CSM[6]);
90+
part.Size[1] = float.Parse(CSM[7]);
91+
part.Size[2] = float.Parse(CSM[8]);
92+
part.UV[0] = int.Parse(CSM[9]);
93+
part.UV[1] = int.Parse(CSM[10]);
94+
csmb.Parts.Add(PartName + Instance, part);
95+
}
96+
}
97+
}

OMI Filetype Library/Forms/Form1.Designer.cs

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OMI Filetype Library/Forms/Form1.cs

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
using MaterialWorker.model;
3030
using ModelsWorker.model;
3131
using UIWorker.model;
32+
using OMI_Filetypes.Classes.Formats;
33+
using OMI_Filetypes.Classes.Workers.CSMBinaryWorker;
34+
using Ionic.Zlib;
3235
#endregion
3336

3437
namespace OMI_Filetype_Library
@@ -40,23 +43,23 @@ public Form1()
4043
InitializeComponent();
4144
}
4245
#region variables
43-
//Containers
46+
//Containers
4447
ColorContainer ColorsContainer;
4548
LanguagesContainer LanguageContainer;
4649
MaterialContainer Materialscontainer;
4750
ModelContainer ModelsContainer;
4851
UIContainer UiContainer;
49-
//Parsers
52+
//Parsers
5053
ColorParser cp = new ColorParser();
5154
LanguagesParser lp = new LanguagesParser();
5255
MaterialParser mp = new MaterialParser();
5356
ModelParser _mp = new ModelParser();
5457
UIParser up = new UIParser();
55-
//Builders
58+
//Builders
5659
ColorBuilder cb = new ColorBuilder();
5760
LanguageBuilder lb = new LanguageBuilder();
58-
//MaterialBuilder mb = new MaterialBuilder();
59-
//ModelBuilder _mb = new ModelBuilder();
61+
MaterialBuilder mb = new MaterialBuilder();
62+
ModelBuilder _mb = new ModelBuilder();
6063
UIBuilder ub = new UIBuilder();
6164

6265
#endregion
@@ -67,7 +70,7 @@ private void button1_Click(object sender, EventArgs e)
6770
{
6871
OpenFileDialog ofd = new OpenFileDialog();
6972
ofd.Filter = "Models file|*.bin";
70-
if(ofd.ShowDialog() == DialogResult.OK)
73+
if (ofd.ShowDialog() == DialogResult.OK)
7174
{
7275
ModelsContainer = _mp.Parse(ofd.FileName);
7376
}
@@ -119,15 +122,15 @@ private void button10_Click(object sender, EventArgs e)
119122

120123
#endregion
121124

122-
#region Opening Files
125+
#region Saving Files
123126

124127
private void button2_Click(object sender, EventArgs e)
125128
{
126129
SaveFileDialog sfd = new SaveFileDialog();
127130
sfd.Filter = "Models file|*.bin";
128-
if(sfd.ShowDialog() == DialogResult.OK)
131+
if (sfd.ShowDialog() == DialogResult.OK)
129132
{
130-
MessageBox.Show("WorkInProgress!");
133+
_mb.Build(ModelsContainer, sfd.FileName);
131134
}
132135
} // models.bin Files
133136

@@ -147,7 +150,7 @@ private void button5_Click(object sender, EventArgs e)
147150
sfd.Filter = "Materials file|entityMaterials.bin";
148151
if (sfd.ShowDialog() == DialogResult.OK)
149152
{
150-
MessageBox.Show("WorkInProgress!");
153+
mb.Build(Materialscontainer, sfd.FileName);
151154
}
152155
} // entityMaterials.bin files
153156

@@ -173,5 +176,68 @@ private void button9_Click(object sender, EventArgs e)
173176

174177
#endregion
175178

179+
private void button11_Click(object sender, EventArgs e)
180+
{
181+
OpenFileDialog opf = new OpenFileDialog();
182+
opf.Filter = "CSM|*.csm";
183+
if (opf.ShowDialog() == DialogResult.OK)
184+
{
185+
string DataIn = File.ReadAllText(opf.FileName);
186+
CSMtoCSMB c2c = new CSMtoCSMB();
187+
CSMBFile newfille = c2c.TryParse(DataIn);
188+
CSMBBuilder Builder = new CSMBBuilder();
189+
//Builder.Build(newfille, opf.FileName + "b");
190+
File.WriteAllBytes(opf.FileName + "bc", compress(File.ReadAllBytes(opf.FileName + "b"), 9));
191+
File.WriteAllBytes(opf.FileName + "c", compress(File.ReadAllBytes(opf.FileName), 9));
192+
}
193+
}
194+
195+
private byte[] compress(byte[] a, int level)
196+
{
197+
using (var ms = new MemoryStream())
198+
{
199+
CompressionLevel compressionLevel = CompressionLevel.Default;
200+
201+
switch (level)
202+
{
203+
case 0:
204+
compressionLevel = CompressionLevel.Level0;
205+
break;
206+
case 1:
207+
compressionLevel = CompressionLevel.Level1;
208+
break;
209+
case 2:
210+
compressionLevel = CompressionLevel.Level2;
211+
break;
212+
case 3:
213+
compressionLevel = CompressionLevel.Level3;
214+
break;
215+
case 4:
216+
compressionLevel = CompressionLevel.Level4;
217+
break;
218+
case 5:
219+
compressionLevel = CompressionLevel.Level5;
220+
break;
221+
case 6:
222+
compressionLevel = CompressionLevel.Level6;
223+
break;
224+
case 7:
225+
compressionLevel = CompressionLevel.Level7;
226+
break;
227+
case 8:
228+
compressionLevel = CompressionLevel.Level8;
229+
break;
230+
case 9:
231+
compressionLevel = CompressionLevel.Level9;
232+
break;
233+
}
234+
235+
using (var compresssor = new DeflateStream(ms, CompressionMode.Compress, compressionLevel))
236+
{
237+
compresssor.Write(a, 0, a.Length);
238+
}
239+
return ms.ToArray();
240+
}
241+
}
176242
}
177243
}

OMI Filetype Library/OMI Filetype Library.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Reference Include="System.Xml" />
5353
</ItemGroup>
5454
<ItemGroup>
55+
<Compile Include="CSMtoCSMB.cs" />
5556
<Compile Include="Forms\Form1.cs">
5657
<SubType>Form</SubType>
5758
</Compile>
3 KB
Binary file not shown.
10 KB
Binary file not shown.
3.5 KB
Binary file not shown.
16 KB
Binary file not shown.

0 commit comments

Comments
 (0)