|
|
|
(VB C#) รบกวนผู้รู้ช่วยเอาตัวอย่างการ SaveFile การเขียนโปรแกรมรูปแบบ แบบนี้ให้ผมหน่อยครับ ผมเซฟแล้วข้อมูลมันมั่วไปหมด |
|
|
|
|
|
|
|
ผมเซฟไฟล์ไม่เป็นครับ ตแนนี้ดึงข้อมูลออกมาแก้ไขได้แล้วแต่เซฟไฟล์ไม่เป็น พยายามทำแล้ว ไฟล์มันไม่กลับไปเป็นข้อมูลต้นฉบับครับ
รบกวน ขอตัวอย่าง หรือบอกวิธีการเซฟไฟล์ให้ผมหน่อยครับ
ขอบคุณมากครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static IfEditor.Ifile;
namespace IfEditor
{
public partial class CharacterEditor : Form
{
public class CharacterStock // based on file struct
{
public byte unknown1;
public uint unknown2;
public string unknown3;
public ushort unknown4;
}
List<CharacterStock> CharacterListing;
List<DescList> DescListMem;
public IF_REGION RegionSelected = IfFile.IF_REGION.Default;
public CharacterEditor()
{
InitializeComponent();
}
private void Uncheck_all_encoding(object sender, EventArgs e)
{
eNGLISHToolStripMenuItem.Checked = false;
jAPANToolStripMenuItem.Checked = false;
tHAIToolStripMenuItem.Checked = false;
oTHERToolStripMenuItem.Checked = false;
autoToolStripMenuItem.Checked = false;
kOREANToolStripMenuItem.Checked = false;
}
private void autoToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Default;
autoToolStripMenuItem.Checked = true;
}
private void eNGLISHToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Usa;
eNGLISHToolStripMenuItem.Checked = true;
}
private void jAPANToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Japan;
jAPANToolStripMenuItem.Checked = true;
}
private void tHAIToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Thaiwan;
tHAIToolStripMenuItem.Checked = true;
}
private void oTHERToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Default;
oTHERToolStripMenuItem.Checked = true;
}
private void kOREANToolStripMenuItem_Click(object sender, EventArgs e)
{
Uncheck_all_encoding(sender, e);
RegionSelected = IffFile.IFF_REGION.Korea;
kOREANToolStripMenuItem.Checked = true;
}
private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog
{
Filter = " IF Pax (Pax*.if)|Pax*.if",
Title = "Open IF Pax"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
CharacterListing = new List<CharacterStock>();
DescListMem = new List<DescList>();
using (BinaryReader reader = new BinaryReader(File.Open(dialog.FileName, FileMode.Open, FileAccess.Read), IffFile.GetFileEncodingByRegion(RegionSelected)))
{
IffFile file = new IffFile();
ushort numberOfRecords = file.GetNumberOfRecords(reader);
file.JumpToFirstRecord(reader);
if (file.CheckMagicNumber(reader))
{
for (int i = 0; i < numberOfRecords; i++)
{
//GetFileEncodingByRegion(RegionSelected).GetString(reader.ReadBytes(XXXXXXXX)); --> exemple for encoding string
long position = reader.BaseStream.Position;
// added the virtual number
CharacterStock item = new CharacterStock
{
Index = i
};
item.unknown1 = reader.ReadByte();
item.unknown2 = reader.ReadUInt32();
item.unknown3 = GetFileEncodingByRegion(RegionSelected).GetString(reader.ReadBytes(40)); //GetFileEncodingByRegion(RegionSelected).GetString(reader.ReadBytes(40)); // 40 Byte long
item.unknown4 = reader.ReadUInt16();
//Adding to the list
CharacterListing.Add(item);
}
reader.Close();
}
UpdateStringList();
}
}
}
private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog
{
Title = "Save Pax IF Pax",
Filter = "Pax IF File (*.if)|*.if"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
if (DescList.SavePart(dialog.FileName, this.CharacterListing, RegionSelected))
{
MessageBox.Show("บันทึกสำเร็จ!!!");
}
else
{
MessageBox.Show("บันทึกไม่สำเร็จ");
}
}
}
private void lstStrings_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.lstStrings.SelectedItems.Count > 0)
{
CharacterStock SelectChar = this.CharacterListing[(int)lstStrings.SelectedItems[0].Tag];
// public byte unknown1; byte <<< ให้อ่านค่าได้ แบบพวกตัวข้างล่าง ทำอย่างไรครับ
// public uint unknown2;
// public string unknown3;
// public ushort unknown4;
////////// แสดงค่าที่หน้าต่าง Textbox ที่หน้าโปรแกรม////////////////////////////////
unknown_1.Text = SelectChar.unknown1;
this.unknown_2.Text = SelectChar.unknown2.ToString();
unknown_3.Text = SelectChar.unknown3;
this.unknown_4.Text = SelectChar.unknown4.ToString;
}
}
private void btnFilter_Click(object sender, EventArgs e)
{
UpdateStringList();
}
private void UpdateStringList()
{
if (CharacterListing != null)
{
if (txtFilter.Text == "")
{
this.lstStrings.Items.Clear();
foreach (CharacterStock str in this.CharacterListing)
{
ListViewItem item = new ListViewItem(str.name)
{
Tag = str.Index
};
this.lstStrings.Items.Add(item);
}
}
else
{
this.lstStrings.Items.Clear();
foreach (CharacterStock str in this.CharacterListing)
{
ListViewItem item = new ListViewItem(str.name)
{
Tag = str.Index
};
bool found = str.name.Contains(txtFilter.Text);
if (found == true)
this.lstStrings.Items.Add(item);
}
}
}
}
private void CharacterName_TextChanged(object sender, EventArgs e)
{
}
private void Model_TextChanged(object sender, EventArgs e)
{
}
private void texture4_TextChanged(object sender, EventArgs e)
{
}
private void itemid_TextChanged(object sender, EventArgs e)
{
}
private void btnApply_Click(object sender, EventArgs e)
{
// if (Name.Text != null)
if (unknown_1.Text != null && unknown_2.Text != null && unknown_3.Text != null && unknown_4.Text != null && CharacterListing != null && this.lstStrings.SelectedItems[0] != null)
{
//unknown_1 << ไม่ทราบว่าต้องเขียนอย่างไร
CharacterListing[(int)this.lstStrings.SelectedItems[0].Tag].unknown3 = this.unknown_3.Text.Replace("\r\n", "\n");
CharacterListing[(int)this.lstStrings.SelectedItems[0].Tag].unknown2 = Convert.ToUInt32(unknown_2.Text);
CharacterListing[(int)this.lstStrings.SelectedItems[0].Tag].unknown4 = Convert.ToUInt32(unknown_4.Text);
UpdateStringList();
}
}
private void texicon_TextChanged(object sender, EventArgs e)
{
}
private void Name_TextChanged(object sender, EventArgs e)
{
}
private void btnApply_Click(object sender, MouseEventArgs e)
{
}
private void Additem_Click(object sender, EventArgs e)
{
}
}
}
Tag : VB.NET, C#
|
|
|
|
|
|
Date :
2017-10-11 12:31:10 |
By :
kom7778 |
View :
793 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Windows Form กับ OpenFileDialog : การเปิด Browse และอัพโหลด Save
|
|
|
|
|
Date :
2017-10-12 17:24:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|