From f906959a09d58c85d87b445fd1791d91bf278bfa Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 15 Nov 2013 17:51:29 -0800 Subject: Use new IO classes --- src/char/int_storage.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/char/int_storage.cpp') diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 205b21e..304a792 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -4,17 +4,17 @@ #include #include -#include #include "../strings/mstring.hpp" #include "../strings/fstring.hpp" #include "../strings/xstring.hpp" +#include "../io/lock.hpp" +#include "../io/read.hpp" + #include "../common/cxxstdio.hpp" #include "../common/db.hpp" #include "../common/extract.hpp" -#include "../common/io.hpp" -#include "../common/lock.hpp" #include "../common/mmo.hpp" #include "../common/socket.hpp" @@ -104,7 +104,7 @@ int inter_storage_init(void) { int c = 0; - std::ifstream in(storage_txt.c_str()); + io::ReadFile in(storage_txt); if (!in.is_open()) { PRINTF("cant't read : %s\n", storage_txt); @@ -112,7 +112,7 @@ int inter_storage_init(void) } FString line; - while (io::getline(in, line)) + while (in.getline(line)) { struct storage s {}; if (extract(line, &s)) @@ -131,21 +131,20 @@ int inter_storage_init(void) } static -void inter_storage_save_sub(struct storage *data, FILE *fp) +void inter_storage_save_sub(struct storage *data, io::WriteFile& fp) { FString line = storage_tostr(data); if (line) - FPRINTF(fp, "%s\n", line); + fp.put_line(line); } //--------------------------------------------------------- // 倉庫データを書き込む int inter_storage_save(void) { - FILE *fp; - int lock; + io::WriteLock fp(storage_txt); - if ((fp = lock_fopen(storage_txt, &lock)) == NULL) + if (!fp.is_open()) { PRINTF("int_storage: cant write [%s] !!! data is lost !!!\n", storage_txt); @@ -153,8 +152,6 @@ int inter_storage_save(void) } for (auto& pair : storage_db) inter_storage_save_sub(&pair.second, fp); - lock_fclose(fp, storage_txt, &lock); -// PRINTF("int_storage: %s saved.\n",storage_txt); return 0; } -- cgit v1.2.3-60-g2f50