public ClassGlobeFile DeSerializeNow(string filename) { ClassGlobeFile c = new ClassGlobeFile(); try { using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFormatter b = new BinaryFormatter(); c = b.Deserialize(fileStream) as ClassGlobeFile; fileStream.Close(); } } catch (Exception e1) { c = new ClassGlobeFile(); MessageBox.Show(e1.Message, "读取文件"); } finally { } return(c); }
public ClassGlobeFile DeSerializeNow(string filename) { ClassGlobeFile c = new ClassGlobeFile(); try { using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFormatter b = new BinaryFormatter(); c = b.Deserialize(fileStream) as ClassGlobeFile; if (c.RecentFilename == null) { c.RecentFilename = new string[20]; } if (c.RecentFilenameKind == null) { c.RecentFilenameKind = new string[20]; } if (c.UserName == null) { c.UserName = new string[100]; c.UserPassword = new string[100]; c.UserLevels = new int[100]; c.UserCount = 1; c.UserName[0] = "AppleLab"; c.UserPassword[0] = "AppleLab"; c.UserLevels[0] = 3; } if (c.SampleFile == null) { c.SampleFile = "TestSample"; } if (c.SamplePath == null) { c.SamplePath = ""; } if (c.demotxt == null) { c.demotxt = ""; } if (c.RecentSampleFilename == null) { c.RecentSampleFilename = new string[20]; } if (c.RecentSampleFilenameKind == null) { c.RecentSampleFilenameKind = new string[20]; } if (c.RecentSampleFilePath == null) { c.RecentSampleFilePath = new string[20]; } if (c.MachineName == null) { c.MachineName = new string[20]; } c.MachineName[0] = "电子蠕变试验机"; c.MachineCount = 1; fileStream.Close(); } } catch (Exception e1) { c = new ClassGlobeFile(); MessageBox.Show(e1.Message, "读取文件"); } finally { } return(c); }