Browse Source

Z991239-1017 #comment fea 远程维护unix2doc实现

陈良瑜80374463 4 years ago
parent
commit
66b9b12d20

+ 35 - 8
Module/mod_RomoteController/remoteBase.cpp

@@ -107,7 +107,7 @@ bool Base_CopyFile(std::string src, std::string dst)
 std::string getCurData()
 {
 	boost::gregorian::date d(boost::gregorian::day_clock::local_day());
-	return (boost::format("%.4d%.2d%.2d") % d.year() % d.month().as_number() % d.day()).str();
+	return (boost::format("%04d%02d%02d") % d.year() % d.month().as_number() % d.day()).str();
 }
 
 //统一切换stricmp,Linux和windows部分都切换,因为很多使用了CSimpleString来比较
@@ -148,20 +148,47 @@ unsigned int get_proc_mem(unsigned int pid) {//获取进程占用内存
 	return vmrss;
 }
 
-std::string getPathName(std::string filePath)
+std::pair<std::string, std::string> getPathName(std::string filePath)
 {
-	return fs::path(filePath).filename().string();
+	return std::make_pair(fs::path(filePath).filename().string(), fs::path(filePath).parent_path().string());
 }
 
-template<typename T>
-void Base_writeIni(std::string section, std::string key, T value, std::string cfgPath)
+bool unix2dos(std::string filename)
+{
+	char c;
+	std::ifstream is(filename.c_str(), std::ios::binary);
+	std::ofstream os("temp.txt", std::ios::binary);
+	while (is.get(c)) {
+		switch (c) {
+		case 0x0d: break;
+		case 0x0a: os.put((char)0x0d); os.put((char)0x0a); break;
+		default: os.put(c); break;
+		}
+	}
+	is.close(); os.close();
+	std::string command = "mv temp.txt " + filename;
+	system(command.c_str());
+	Base_DeleteFile("temp.txt");
+	return EXIT_SUCCESS;
+}
+
+void Base_writeIni(std::string section, std::string key, std::string value, std::string cfgPath)
 {
 	boost::property_tree::ptree lvptProperties;
 	boost::property_tree::ini_parser::read_ini(cfgPath, lvptProperties);
-	boost::property_tree::basic_ptree<std::string, std::string> lvbtItems = lvptProperties.get_child(section);
-
+	auto curPro = lvptProperties.get_child(section);
 
-		lvptProperties.add<T>(key, value);
+	if (curPro.find(key) == curPro.not_found())
+		lvptProperties.add<std::string>(section + "." + key, value);
+	else
+		lvptProperties.put<std::string>(section + "." + key, value);
 
 	boost::property_tree::ini_parser::write_ini(cfgPath, lvptProperties);
+	unix2dos(cfgPath);
+	
+}
+
+bool Base_isDirectory(std::string filePath)
+{
+	return fs::is_directory(filePath);
 }

+ 4 - 3
Module/mod_RomoteController/remoteBase.h

@@ -23,7 +23,8 @@ std::pair<bool, int> Base_readFile(std::string filePath, uintmax_t start, char*
 
 unsigned int get_proc_mem(unsigned int pid);
 
-std::string getPathName(std::string filePath);
+std::pair<std::string, std::string> getPathName(std::string filePath);
 
-template<typename T>
-void Base_writeIni(std::string section, std::string key, T value, std::string cfgPath);
+void Base_writeIni(std::string section, std::string key, std::string value, std::string cfgPath);
+
+bool Base_isDirectory(std::string filePath);