public static void exportUserData(String filePath_Bin,SerializeAble SAobj) { if (filePath_Bin == null) { return; } ArrayTxts_Head.Clear(); ArrayTxts_Java.Clear(); FileStream fs_bin = null; String resName = null; String name = null; try { if (File.Exists(filePath_Bin)) { fs_bin = File.Open(filePath_Bin, FileMode.Truncate); } else { fs_bin = File.Open(filePath_Bin, FileMode.OpenOrCreate); } try { resName = filePath_Bin.Substring(filePath_Bin.LastIndexOf('\\') + 1); name = resName.Substring(0, resName.LastIndexOf('.')); } catch (Exception e) { Console.WriteLine(e.Message); } if(resName == null) { resName = "NULL"; } if (name == null) { name = ""; } ArrayTxts_Head.Add("//=============================AnimationData============================="); ArrayTxts_Head.Add(" "); ArrayTxts_Head.Add("#define C2D_NAME_" + name + " \"" + resName + "\""); ArrayTxts_Head.Add(" "); ArrayTxts_Java.Add("//=============================AnimationData============================="); ArrayTxts_Java.Add(" "); ArrayTxts_Java.Add("public static final String C2D_NAME_" + name + " = \"" + resName + "\";"); ArrayTxts_Java.Add(" "); SAobj.ExportObject(fs_bin); } catch (Exception e) { String err = "未知"; if (e != null && e.Message != null) { err = e.Message; } MessageBox.Show("导出数据过程中发生了异常:“" + err + "”", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(e.Message); } finally { if (fs_bin != null) { try { fs_bin.Flush(); fs_bin.Close(); fs_bin = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //处理Include文本---------------------------------------------------------------------- saveConstTxt(ArrayTxts_Java, name, true); saveConstTxt(ArrayTxts_Head, name, false); }
public static void exportUserData(String filePath_Bin, SerializeAble SAobj) { if (filePath_Bin == null) { return; } ArrayTxts_Head.Clear(); ArrayTxts_Java.Clear(); FileStream fs_bin = null; String resName = null; String name = null; try { if (File.Exists(filePath_Bin)) { fs_bin = File.Open(filePath_Bin, FileMode.Truncate); } else { fs_bin = File.Open(filePath_Bin, FileMode.OpenOrCreate); } try { resName = filePath_Bin.Substring(filePath_Bin.LastIndexOf('\\') + 1); name = resName.Substring(0, resName.LastIndexOf('.')); } catch (Exception e) { Console.WriteLine(e.Message); } if (resName == null) { resName = "NULL"; } if (name == null) { name = ""; } ArrayTxts_Head.Add("//=============================AnimationData============================="); ArrayTxts_Head.Add(" "); ArrayTxts_Head.Add("#define C2D_NAME_" + name + " \"" + resName + "\""); ArrayTxts_Head.Add(" "); ArrayTxts_Java.Add("//=============================AnimationData============================="); ArrayTxts_Java.Add(" "); ArrayTxts_Java.Add("public static final String C2D_NAME_" + name + " = \"" + resName + "\";"); ArrayTxts_Java.Add(" "); SAobj.ExportObject(fs_bin); } catch (Exception e) { String err = "未知"; if (e != null && e.Message != null) { err = e.Message; } MessageBox.Show("导出数据过程中发生了异常:“" + err + "”", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(e.Message); } finally { if (fs_bin != null) { try { fs_bin.Flush(); fs_bin.Close(); fs_bin = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //处理Include文本---------------------------------------------------------------------- saveConstTxt(ArrayTxts_Java, name, true); saveConstTxt(ArrayTxts_Head, name, false); }
public bool saveUserData(String filePath, SerializeAble SAobj) { if (filePath == null) { return false; } FileStream fs = null; String strFilePathTemp = filePath + ".temp"; bool exceptionHappend = false; String excetionInSave = ""; try { if (File.Exists(strFilePathTemp)) { fs = File.Open(strFilePathTemp, FileMode.Truncate); } else { fs = File.Open(strFilePathTemp, FileMode.OpenOrCreate); } IOUtil.writeInt(fs, Consts.softWareVersion);//保存版本信息 SAobj.WriteObject(fs); } catch (Exception e) { exceptionHappend = true; excetionInSave = e.Message; Console.WriteLine(e.StackTrace); } finally { if (fs != null) { try { fs.Flush(); fs.Close(); fs = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } if (exceptionHappend) { MessageBox.Show("保存失败,保存过程中发生了异常【" + excetionInSave + "】!", "警报", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } IOUtil.Copy(strFilePathTemp, filePath, true); //生成备份 String strFolderBak = filePath.Substring(0, filePath.LastIndexOf('\\')); String fileName = filePath.Substring(filePath.LastIndexOf('\\'), filePath.Length - strFolderBak.Length); strFolderBak += "\\BAKS"; if (!Directory.Exists(strFolderBak)) { Directory.CreateDirectory(strFolderBak); } fileName = fileName.Substring(0, fileName.LastIndexOf('.')); //系统时间 String timeString = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); fileName = strFolderBak + fileName + "_" + timeString + ".bak"; IOUtil.Copy(strFilePathTemp, fileName, true); File.Delete(strFilePathTemp); return true; }
public bool saveUserData(String filePath, SerializeAble SAobj) { if (filePath == null) { return(false); } FileStream fs = null; String strFilePathTemp = filePath + ".temp"; bool exceptionHappend = false; String excetionInSave = ""; try { if (File.Exists(strFilePathTemp)) { fs = File.Open(strFilePathTemp, FileMode.Truncate); } else { fs = File.Open(strFilePathTemp, FileMode.OpenOrCreate); } IOUtil.writeInt(fs, Consts.softWareVersion);//保存版本信息 SAobj.WriteObject(fs); } catch (Exception e) { exceptionHappend = true; excetionInSave = e.Message; Console.WriteLine(e.StackTrace); } finally { if (fs != null) { try { fs.Flush(); fs.Close(); fs = null; } catch (Exception ex) { Console.WriteLine(ex.Message); } } } if (exceptionHappend) { MessageBox.Show("保存失败,保存过程中发生了异常【" + excetionInSave + "】!", "警报", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } IOUtil.Copy(strFilePathTemp, filePath, true); //生成备份 String strFolderBak = filePath.Substring(0, filePath.LastIndexOf('\\')); String fileName = filePath.Substring(filePath.LastIndexOf('\\'), filePath.Length - strFolderBak.Length); strFolderBak += "\\BAKS"; if (!Directory.Exists(strFolderBak)) { Directory.CreateDirectory(strFolderBak); } fileName = fileName.Substring(0, fileName.LastIndexOf('.')); //系统时间 String timeString = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); fileName = strFolderBak + fileName + "_" + timeString + ".bak"; IOUtil.Copy(strFilePathTemp, fileName, true); File.Delete(strFilePathTemp); return(true); }