• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

論理回路シミュレータ


コミットメタ情報

リビジョンee19ff67f9ae7d423a674d92ae9d3ae29f40c0df (tree)
日時2017-07-13 08:16:26
作者OkaMitio <oka_mitio@yaho...>
コミッターOkaMitio

ログメッセージ

Ver0.84のファイルフォーマット

変更サマリ

差分

--- a/edit.cpp
+++ b/edit.cpp
@@ -5,6 +5,9 @@
55
66 extern HWND hMainWindow;
77
8+extern int filever;
9+extern void GetFileVer(std::ifstream &f);
10+
811 namespace Edit
912 {
1013 extern vector2D coordinates1;
@@ -257,7 +260,7 @@ void Data::CopyRange(bool Erase,bool Copy)
257260 _splitpath_s(ExePath,drive,MAX_PATH+1,dir,MAX_PATH+1,NULL,0,NULL,0);
258261 _makepath_s(FileEdit,MAX_PATH+1,drive,dir,"FileUsedByEditingOfAst","log");
259262 std::ofstream f(FileEdit);
260- f << "Ast0.8" << std::endl <<std::endl;
263+ f << "Ast0.84" << std::endl <<std::endl;
261264 f << copy_data;
262265 f.close();
263266 }
@@ -275,20 +278,21 @@ void LoadCopiedData()
275278
276279 if(f)
277280 {
278- char s[SIZE_OF_LABEL_NAME];
279- f.getline(s,SIZE_OF_LABEL_NAME);
280- if(strcmp(s,"Ast0.8")==0)
281+ GetFileVer(f);
282+ if (filever == -1)
283+ {
284+ MessageBox(hMainWindow, "バージョンの異なるファイルです", "エラー", MB_OK);
285+ }
286+ else
281287 {
282288 copy_data.Clear();
283289 f >> copy_data;
284- if(!f.good())
290+ if (!f.good())
285291 {
286292 copy_data.Clear();
287- MessageBox(hMainWindow,"ファイルが壊れています","エラー",MB_OK);
293+ MessageBox(hMainWindow, "ファイルが壊れています", "エラー", MB_OK);
288294 }
289295 }
290- else
291- MessageBox(hMainWindow,"バージョンの異なるファイルです","エラー",MB_OK);
292296 f.close();
293297 }
294298 }
--- a/fileio.cpp
+++ b/fileio.cpp
@@ -3,6 +3,8 @@
33 #include<iostream>
44 #include<fstream>
55
6+int filever; //バージョン 0:0.8 1:0.84
7+const char *verstr[] = { "Ast0.8","Ast0.84" };
68
79
810 extern HWND hMainWindow;
@@ -22,6 +24,14 @@ namespace FileIO
2224 }
2325
2426
27+void GetFileVer(std::ifstream &f)
28+{
29+ char s[SIZE_OF_LABEL_NAME];
30+ f.getline(s, SIZE_OF_LABEL_NAME);
31+ filever = -1;
32+ for (int i = 0; i < 2; i++)if (strcmp(s, verstr[i])==0)filever = i;
33+}
34+
2535 std::istream &operator>>(std::istream &stream,vector2D &v)
2636 {
2737 stream >> v.x >> v.y;
@@ -278,7 +288,10 @@ std::istream &operator>>(std::istream &stream,Module &m)
278288 {
279289 unsigned int size;
280290
281- m.d = RIGHT;
291+ if (filever >= 1)
292+ stream >> (int&)m.d;
293+ else
294+ m.d = RIGHT;
282295
283296 stream >> m.center;
284297 stream >> m.internal_half_width;
@@ -349,6 +362,7 @@ std::istream &operator>>(std::istream &stream,Module &m)
349362
350363 std::ostream &operator<<(std::ostream &stream,Module m)
351364 {
365+ stream << m.d << " ";
352366 stream << m.center << " ";
353367 stream << m.internal_half_width << " ";
354368 stream << m.internal_half_height << " ";
@@ -536,7 +550,7 @@ bool SaveAs(Data d,char *szF,char *szFT)
536550 if(GetSaveFileName(&ofn) == 0) return false;
537551
538552 std::ofstream f(szF);
539- f << "Ast0.8" << std::endl << std::endl;
553+ f << "Ast0.84" << std::endl << std::endl;
540554 f << d;
541555 f.close();
542556 return true;
@@ -550,7 +564,7 @@ bool Save()
550564 std::ofstream f(FileIO::szFile);
551565 if(f)
552566 {
553- f << "Ast0.8" << std::endl << std::endl;
567+ f << "Ast0.84" << std::endl << std::endl;
554568 f << main_data;
555569 f.close();
556570 }
@@ -563,29 +577,30 @@ bool LoadData()
563577 std::ifstream f(FileIO::szFile);
564578 if(f)
565579 {
566- char s[SIZE_OF_LABEL_NAME];
567- f.getline(s,SIZE_OF_LABEL_NAME);
568- if(strcmp(s,"Ast0.8")==0)
580+ GetFileVer(f);
581+ if(filever==-1)
582+ {
583+ main_data.Clear();
584+ FileIO::szFile[0] = 0;
585+ FileIO::szFileTitle[0] = 0;
586+ MessageBox(hMainWindow, "扱えないファイルフォーマットのファイルです", "エラー", MB_OK);
587+ f.close();
588+ return false;
589+ }
590+ else
569591 {
570592 main_data.Clear();
571593 f >> main_data;
572- if(!f.good())
594+ if (!f.good())
573595 {
574596 main_data.Clear();
575- FileIO::szFile[0]=0;
576- FileIO::szFileTitle[0]=0;
577- MessageBox(hMainWindow,"ファイルが壊れています","エラー",MB_OK);
597+ FileIO::szFile[0] = 0;
598+ FileIO::szFileTitle[0] = 0;
599+ MessageBox(hMainWindow, "ファイルが壊れています", "エラー", MB_OK);
600+ f.close();
578601 return false;
579602 }
580603 }
581- else
582- {
583- main_data.Clear();
584- FileIO::szFile[0]=0;
585- FileIO::szFileTitle[0]=0;
586- MessageBox(hMainWindow,"ファイルフォーマットの異なるファイルです","エラー",MB_OK);
587- return false;
588- }
589604 f.close();
590605 }
591606 return true;
@@ -692,25 +707,26 @@ bool LoadModule()
692707
693708 std::ifstream f(szFile_Modul);
694709 if(!f)return false;
695-
696- char s[SIZE_OF_LABEL_NAME];
697- f.getline(s,SIZE_OF_LABEL_NAME);
698- if(strcmp(s,"Ast0.8")==0)
710+
711+ GetFileVer(f);
712+ if (filever == -1)
713+ {
714+ MessageBox(hMainWindow, "扱えないファイルフォーマットのファイルです", "エラー", MB_OK);
715+ f.close();
716+ return false;
717+ }
718+ else
699719 {
700720 Place::NewModule.Clear();
701721 f >> (Data&)Place::NewModule;
702- if(!f.good())
722+ if (!f.good())
703723 {
704724 Place::NewModule.Clear();
705- MessageBox(hMainWindow,"ファイルが壊れています","エラー",MB_OK);
725+ MessageBox(hMainWindow, "ファイルが壊れています", "エラー", MB_OK);
726+ f.close();
706727 return false;
707728 }
708729 }
709- else
710- {
711- MessageBox(hMainWindow,"バージョンの異なるファイルです","エラー",MB_OK);
712- return false;
713- }
714730 f.close();
715731
716732 if(Place::NewModule.nInput()==0 || Place::NewModule.nOutput()==0)