using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using LuaInterface;
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace LuaFramework
|
|
{
|
|
public static class FileTools
|
|
{
|
|
private static List<string> paths = new List<string>();
|
|
private static StringBuilder files = new StringBuilder();
|
|
|
|
private static List<string> str = new List<string>();
|
|
|
|
private static List<string> cfg_names_list = new List<string>();
|
|
private static List<string> fina_list = new List<string>();
|
|
//返回的是内容组成的字符串
|
|
public static string GetPathFiles(string path, string pre = "", string match_str = "")
|
|
{
|
|
paths.Clear();
|
|
files.Clear();
|
|
if (Directory.Exists(path))
|
|
{
|
|
Recursive(path, pre, match_str);
|
|
}
|
|
else
|
|
{
|
|
files.Append("null");
|
|
}
|
|
return files.ToString();
|
|
}
|
|
|
|
//判断路径是否存在
|
|
public static bool CheckPathExists(string path)
|
|
{
|
|
bool has_path = false;
|
|
has_path = Directory.Exists(path);
|
|
return has_path;
|
|
}
|
|
|
|
/// 遍历目录及其子目录 pre是只有包含这个符号的才会添加
|
|
private static void Recursive(string path, string pre, string match_str)
|
|
{
|
|
string[] names = Directory.GetFiles(path);
|
|
string[] dirs = Directory.GetDirectories(path);
|
|
foreach (string filename in names)
|
|
{
|
|
string ext = Path.GetExtension(filename);
|
|
if (!ext.Equals(match_str)) continue;
|
|
if (pre != "" && !filename.Contains(pre)) continue;
|
|
string real_name = filename.Replace('\\', '/');
|
|
files.Append(real_name);
|
|
files.Append("\n");
|
|
}
|
|
foreach (string dir in dirs)
|
|
{
|
|
paths.Add(dir.Replace('\\', '/'));
|
|
Recursive(dir, pre, match_str);
|
|
}
|
|
}
|
|
|
|
public static void OutPutValue(string file_name, string value_str)
|
|
{
|
|
str.Clear();
|
|
if (!string.IsNullOrEmpty(value_str))
|
|
{
|
|
string[] str_list = value_str.Split('&');
|
|
foreach (string s in str_list)
|
|
{
|
|
str.Add(s);
|
|
}
|
|
|
|
if (str.Count >= 0)
|
|
{
|
|
try
|
|
{
|
|
//string root_str = Application.dataPath;
|
|
//if (!Application.isEditor)
|
|
//{
|
|
// root_str = root_str.Replace("ClientApp_Data", "");
|
|
// root_str = root_str.Replace("localTest", "");
|
|
// root_str = root_str.Replace("app", "");
|
|
//}
|
|
//root_str = root_str.Replace("Assets", "");
|
|
//string target_path = root_str + "/" + file_name + ".csv";
|
|
string target_path = Application.dataPath.Replace("Assets", "") + "/" + file_name + ".csv";
|
|
File.WriteAllLines(target_path, str.ToArray(), Encoding.GetEncoding("GB2312"));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void MatchCfg(string path, string pre = "", string match_str = "", string Config = "")
|
|
{
|
|
paths.Clear();
|
|
files.Clear();
|
|
cfg_names_list.Clear();
|
|
fina_list.Clear();
|
|
byte[] bytes = new byte[1024 * 1024];
|
|
string root_path = Application.dataPath;
|
|
if (Directory.Exists(path))
|
|
{
|
|
Recursive(path, pre, match_str);
|
|
}
|
|
else
|
|
{
|
|
files.Append("null");
|
|
}
|
|
if (files.Length > 0)
|
|
{
|
|
string str = files.ToString();
|
|
string[] arr = str.Split('\n');
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
string cfg_path = arr[i];
|
|
string[] arr2 = Regex.Split(cfg_path, "Lua/", RegexOptions.IgnoreCase);
|
|
string s = arr2[arr2.Length - 1].Replace(".lua", "").Replace('/', '.');
|
|
cfg_names_list.Add(s);
|
|
}
|
|
}
|
|
Config = Config + ".lua";
|
|
if (File.Exists(Config))
|
|
{
|
|
FileStream fs = new FileStream(Config, FileMode.Open);
|
|
int count = (int)fs.Length;
|
|
fs.Read(bytes, 0, count);
|
|
string str = Encoding.UTF8.GetString(bytes);
|
|
if (!string.IsNullOrEmpty(str))
|
|
{
|
|
string title = "是否引用配置,lua名,配置文件名&";
|
|
fina_list.Add(title);
|
|
for (int i = 0; i < cfg_names_list.Count; i++)
|
|
{
|
|
bool use_cfg = str.Contains(cfg_names_list[i]);
|
|
string desc = "";
|
|
if (use_cfg == false)
|
|
{
|
|
desc = "未引用此配置";
|
|
}
|
|
string[] arr3 = cfg_names_list[i].Split('.');
|
|
string file_name = arr3[arr3.Length - 1];
|
|
string name = cfg_names_list[i];
|
|
string fina_str = desc + "," + file_name + "," + name + "&";
|
|
fina_list.Add(fina_str);
|
|
}
|
|
}
|
|
fs.Close();
|
|
}
|
|
|
|
if (fina_list.Count > 0)
|
|
{
|
|
string target_path = Application.dataPath.Replace("Assets", "") + "/" + "配置关系表" + ".csv";
|
|
File.WriteAllLines(target_path, fina_list.ToArray(), Encoding.GetEncoding("GB2312"));
|
|
Debug.Log("配置关系表生成完成");
|
|
}
|
|
}
|
|
}
|
|
}
|