t-suw****@users*****
t-suw****@users*****
2007年 11月 19日 (月) 23:13:36 JST
Index: AquaSKK/ChangeLog diff -u AquaSKK/ChangeLog:1.54 AquaSKK/ChangeLog:1.55 --- AquaSKK/ChangeLog:1.54 Sun Nov 11 14:18:52 2007 +++ AquaSKK/ChangeLog Mon Nov 19 23:13:36 2007 @@ -1,3 +1,8 @@ +2007-11-19 Tomotaka SUWA <t.suw****@mac*****> + + * SKKDictionary.cpp: èªåæ´æ°è¾æ¸ã®ãã¦ã³ãã¼ãã¯å¥åã§è¡ããããã + ã¯ã¼ã¯åææã«ãè¾æ¸ãå£ããªãããã«æ¹åã + 2007-11-11 Tomotaka SUWA <t.suw****@mac*****> * BIM.cpp, ParentInputMode.*, *ConversionMode.cpp, Index: AquaSKK/SKKDictionary.cpp diff -u AquaSKK/SKKDictionary.cpp:1.16 AquaSKK/SKKDictionary.cpp:1.17 --- AquaSKK/SKKDictionary.cpp:1.16 Wed Sep 19 22:57:17 2007 +++ AquaSKK/SKKDictionary.cpp Mon Nov 19 23:13:36 2007 @@ -1,10 +1,10 @@ /* - $Id: SKKDictionary.cpp,v 1.16 2007/09/19 13:57:17 t-suwa Exp $ + $Id: SKKDictionary.cpp,v 1.17 2007/11/19 14:13:36 t-suwa Exp $ MacOS X implementation of the SKK input method. Copyright (C) 2002 phonohawk - Copyright (C) 2005-2006 Tomotaka SUWA <t.suw****@mac*****> + Copyright (C) 2005-2007 Tomotaka SUWA <t.suw****@mac*****> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #include <iostream> #include <fstream> +#include <sstream> #include <algorithm> #include <numeric> #include <ctime> @@ -333,28 +334,32 @@ session << "Connection: close" << std::endl; session << std::endl; - // ã¬ã¹ãã³ã¹ + // æ´æ°ãããè¾æ¸ã®ãµã¤ãºãåå¾ãã std::string response; - bool modified = false; - while(true) { - getline(session, response); - if(response.find("200 OK") != std::string::npos) { - modified = true; + int length = 0; + while(std::getline(session, response) && response != "\r") { + if(response.find("Content-Length") != std::string::npos) { + std::istringstream buf(response); + buf >> response >> length; } - if(response == "\r") break; } - // å¤æ´ããã¦ããã°ããã¦ã³ãã¼ããã¦ãªãã¼ããã - if(modified) { - std::ofstream ofs(obj->path_.c_str()); - while(session.good()) { - getline(session, response); + // æ´æ°ããã¦ãããªããã¦ã³ãã¼ããã + if(length) { + std::string path(obj->path_); + path += ".download"; + std::ofstream ofs(path.c_str()); + while(std::getline(session, response)) { ofs << response << std::endl; } ofs.close(); - obj->reloadContainer(); - std::cerr << "SKKAutoUpdateDictionary: " << obj->path_ << " has been updated" << std::endl; + // å®å ¨ã«ãã¦ã³ãã¼ãã§ããããªãã¼ã + if(stat(path.c_str(), &st) == 0 && st.st_size == length) { + rename(path.c_str(), obj->path_.c_str()); + obj->reloadContainer(); + std::cerr << "SKKAutoUpdateDictionary: " << obj->path_ << " has been updated" << std::endl; + } } } else { std::cerr << "SKKAutoUpdateDictionary: can't connect to [" << obj->host_ << "]" << std::endl;