Skip to content

Commit

Permalink
Исправлены настройки
Browse files Browse the repository at this point in the history
  • Loading branch information
VaIeroK committed Aug 18, 2022
1 parent 508505d commit 0cd3192
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 82 deletions.
48 changes: 26 additions & 22 deletions Source/App/ObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,31 +251,33 @@ private string[] GameMtlParser(string filename)
{
List<string> materials = new List<string>();

var xr_loader = new XRayLoader();

using (var r = new BinaryReader(new FileStream(filename, FileMode.Open)))
if (File.Exists(filename))
{
xr_loader.SetStream(r.BaseStream);
xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk((int)MTL.GAMEMTLS_CHUNK_MTLS, false, true));
var xr_loader = new XRayLoader();
using (var r = new BinaryReader(new FileStream(filename, FileMode.Open)))
{
xr_loader.SetStream(r.BaseStream);
xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk((int)MTL.GAMEMTLS_CHUNK_MTLS, false, true));

int id = 0;
uint size;
int id = 0;
uint size;

while (true)
{
if (!xr_loader.find_chunk(id)) break;
while (true)
{
if (!xr_loader.find_chunk(id)) break;

Stream temp = xr_loader.reader.BaseStream;
Stream temp = xr_loader.reader.BaseStream;

if (!xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk(id, false, true))) break;
if (!xr_loader.SetData(xr_loader.find_and_return_chunk_in_chunk(id, false, true))) break;

size = xr_loader.find_chunkSize((int)MTL.GAMEMTL_CHUNK_MAIN);
if (size == 0) break;
xr_loader.ReadBytes(4);
materials.Add(xr_loader.read_stringZ());
size = xr_loader.find_chunkSize((int)MTL.GAMEMTL_CHUNK_MAIN);
if (size == 0) break;
xr_loader.ReadBytes(4);
materials.Add(xr_loader.read_stringZ());

id++;
xr_loader.SetStream(temp);
id++;
xr_loader.SetStream(temp);
}
}
}
string[] ret = materials.ToArray();
Expand All @@ -293,8 +295,6 @@ public void ReloadGameMtl(string filename)
for (int i = 0; i < m_Object.bones.Count; i++)
CreateBoneGroupBox(i, m_Object.bones[i]);
}
else
Msg("ReloadGameMtl: Error!\nObject is null. Please report this bug for developer.");
}

private void FastSaveObject(string filename)
Expand Down Expand Up @@ -1182,14 +1182,18 @@ private void PageResize(object sender, EventArgs e)

private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
string old_game_mtl = "";
pSettings.Load("GameMtlPath", ref old_game_mtl);

Settings ProgramSettings = new Settings(this.pSettings, this, this);
ProgramSettings.ShowDialog();

string game_mtl = "";
pSettings.Load("GameMtlPath", ref game_mtl);
pSettings.LoadState("SplitNormalsChbx", ref NORMALS_DEFAULT, true);
if (File.Exists(game_mtl))
game_materials = GameMtlParser(game_mtl);

if (old_game_mtl != game_mtl)
ReloadGameMtl(game_mtl);

bool Debug = false;
pSettings.LoadState("Debug", ref Debug);
Expand Down
6 changes: 4 additions & 2 deletions Source/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ public class IniFile // revision 11
public IniFile(string IniPath = null)
{
if (!File.Exists(IniPath))
File.Create(IniPath);

{
var myFile = File.Create(IniPath);
myFile.Close();
}
string file_name = (IniPath ?? EXE + ".ini");
Ini = new FileInfo(file_name);
}
Expand Down
9 changes: 5 additions & 4 deletions Source/App/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 86 additions & 53 deletions Source/App/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class Settings : Form
private EditorSettings pSettings = null;
private Form EditorForm = null;
private Object_Editor Editor = null;

public Settings(EditorSettings settings, Form main_form, Object_Editor editor)
{
InitializeComponent();
Expand All @@ -24,19 +25,6 @@ public Settings(EditorSettings settings, Form main_form, Object_Editor editor)
Editor = editor;
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.Filter = "Xr file|*.xr";

if (ofd.ShowDialog() == DialogResult.OK)
{
GameMtlPath.Text = ofd.FileName;
Editor.ReloadGameMtl(GameMtlPath.Text);
}
}

public void SaveParams(object sender, FormClosingEventArgs e)
{
pSettings.SaveVersion();
Expand Down Expand Up @@ -170,44 +158,6 @@ private void StripifyCheck(object sender, EventArgs e)
ProgressiveMeshes.Checked = false;
}

private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.Filter = "Ltx file|*.ltx";

if (ofd.ShowDialog() == DialogResult.OK)
{
FSLtxPath.Text = ofd.FileName;

string gamedata_path = ofd.FileName.Substring(0, ofd.FileName.LastIndexOf('\\')) + "\\" + GetFSPath(ofd.FileName, "$game_data$");

if (File.Exists(gamedata_path + "gamemtl.xr"))
{
GameMtlPath.Text = gamedata_path + "gamemtl.xr";
Editor.ReloadGameMtl(GameMtlPath.Text);
}
TexturesPath.Text = gamedata_path + GetFSPath(ofd.FileName, "$game_textures$");

int slash_idx = TexturesPath.Text.LastIndexOf('\\');
if (slash_idx == TexturesPath.Text.Count() - 1)
TexturesPath.Text = TexturesPath.Text.Substring(0, TexturesPath.Text.LastIndexOf('\\'));
}
}

private void button3_Click(object sender, EventArgs e)
{
FolderSelectDialog folderSelectDialog = new FolderSelectDialog();
if (folderSelectDialog.ShowDialog())
{
string fname = folderSelectDialog.FileName;
int slash_idx = fname.LastIndexOf('\\');
if (slash_idx == fname.Count() - 1)
fname = fname.Substring(0, fname.LastIndexOf('\\'));
TexturesPath.Text = fname;
}
}

private string GetFSPath(string filename, string key)
{
using (StreamReader file = new StreamReader(filename))
Expand Down Expand Up @@ -236,7 +186,7 @@ private string GetFSPath(string filename, string key)
file.Close();
}

return "";
return null;
}

private bool IsTextCorrect(string text)
Expand Down Expand Up @@ -274,7 +224,7 @@ private string GetCorrectString(string text)
return ret_text;
}

private void button4_Click(object sender, EventArgs e)
private void FindImagePath(object sender, EventArgs e)
{
FolderSelectDialog folderSelectDialog = new FolderSelectDialog();
if (folderSelectDialog.ShowDialog())
Expand All @@ -286,5 +236,88 @@ private void button4_Click(object sender, EventArgs e)
ImagePath.Text = fname;
}
}

private void FindFsPath(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.Filter = "Ltx file|*.ltx";

if (ofd.ShowDialog() == DialogResult.OK)
{
FSLtxPath.Text = ofd.FileName;

if (GetFSPath(ofd.FileName, "$game_data$") != null)
{
string gamedata_path = ofd.FileName.Substring(0, ofd.FileName.LastIndexOf('\\')) + "\\" + GetFSPath(ofd.FileName, "$game_data$");

if (File.Exists(gamedata_path + "gamemtl.xr"))
{
GameMtlPath.Text = gamedata_path + "gamemtl.xr";
}

if (GetFSPath(ofd.FileName, "$game_textures$") != null)
{
TexturesPath.Text = gamedata_path + GetFSPath(ofd.FileName, "$game_textures$");

int slash_idx = TexturesPath.Text.LastIndexOf('\\');
if (slash_idx == TexturesPath.Text.Count() - 1)
TexturesPath.Text = TexturesPath.Text.Substring(0, TexturesPath.Text.LastIndexOf('\\'));
}
}
}
}

private void FindTexturesPath(object sender, EventArgs e)
{
FolderSelectDialog folderSelectDialog = new FolderSelectDialog();
if (folderSelectDialog.ShowDialog())
{
string fname = folderSelectDialog.FileName;
int slash_idx = fname.LastIndexOf('\\');
if (slash_idx == fname.Count() - 1)
fname = fname.Substring(0, fname.LastIndexOf('\\'));
TexturesPath.Text = fname;
}
}

private void FindGameMtlPath(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.Filter = "Xr file|*.xr";

if (ofd.ShowDialog() == DialogResult.OK)
{
GameMtlPath.Text = ofd.FileName;
}
}

private void FsPathTextChanged(object sender, EventArgs e)
{
if (Path.GetExtension(FSLtxPath.Text) == ".ltx" && File.Exists(FSLtxPath.Text))
{
string FileName = FSLtxPath.Text;

if (GetFSPath(FileName, "$game_data$") != null)
{
string gamedata_path = FileName.Substring(0, FileName.LastIndexOf('\\')) + "\\" + GetFSPath(FileName, "$game_data$");

if (File.Exists(gamedata_path + "gamemtl.xr"))
{
GameMtlPath.Text = gamedata_path + "gamemtl.xr";
}

if (GetFSPath(FileName, "$game_textures$") != null)
{
TexturesPath.Text = gamedata_path + GetFSPath(FileName, "$game_textures$");

int slash_idx = TexturesPath.Text.LastIndexOf('\\');
if (slash_idx == TexturesPath.Text.Count() - 1)
TexturesPath.Text = TexturesPath.Text.Substring(0, TexturesPath.Text.LastIndexOf('\\'));
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion Source/App/UiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class Object_Editor
public void InitSettings()
{
string file_path = AppPath() + "\\Settings.ini";
bool SettingsExist = File.Exists(file_path);
pSettings = new EditorSettings(file_path);

bool NoCompress = false;
Expand All @@ -22,7 +23,8 @@ public void InitSettings()

if (!pSettings.CheckVers())
{
Msg("Settings version conflict! Load defaults.");
if (SettingsExist)
Msg("Settings version conflict! Load defaults.");
Settings settings = new Settings(pSettings, this, this);
settings.Settings_Load(null, null); // Load defaults
settings.SaveParams(null, null); // Save defaults
Expand Down

0 comments on commit 0cd3192

Please sign in to comment.