public void FindTxt() { if (checkDataError()) { return; } OpenDialogFile ofn = new OpenDialogFile(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "All Files\0*.*\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; string path = Application.streamingAssetsPath; path = path.Replace('/', '\\'); ofn.title = "选择索引文件"; //注意 一下项目不一定要全选 但是0x00000008项不要缺少 ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR if (DllBox.GetOpenFileName(ofn)) { gameObject.transform.Find("LogText").GetComponent <Text>().text = ofn.file; data.TxtPath = ofn.file; } }
private void DirectPick() { if (DirectItems.Values.Count <= 0) { DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0); return; } text.text = "开始执行"; foreach (GameObject obj in DirectItems.Values) { DataItem data = obj.GetComponent <ItemScript>().Data; string[] baseNames = Directory.GetFiles(data.BaseDirPath); string[] targetNames = Directory.GetFiles(data.TargetDirPath); if (!Directory.Exists(LogPath)) { Directory.CreateDirectory(LogPath); } FileStream fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now); sw.WriteLine("源目录" + data.BaseDirPath); sw.WriteLine("目标目录" + data.TargetDirPath); sw.WriteLine("索引目录" + data.FolderPath); sw.WriteLine("索引文件" + data.TxtPath); sw.WriteLine("移动张数" + data.Number); int count = 0; for (int j = 0; j < baseNames.Length; j++) { Debug.Log(targetNames); Debug.Log(data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, "")); if (targetNames.Contains(data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""))) { sw.WriteLine("跳过文件" + baseNames[j] + "目标已存在"); continue; } count++; if (count > data.Number) { break; } try { File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), true); sw.WriteLine("根据" + baseNames[j] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath); } catch { sw.WriteLine("复制失败了" + baseNames[j]); } } sw.Close(); fs.Close(); } text.text = "执行完毕"; }
private bool checkDataError() { if (data.id == 0) { DllBox.MessageBox(IntPtr.Zero, "为什么会没有ID,世界人民都震惊了!!!", "异常", 0); return(true); } return(false); }
private bool modeCheck() { if (mode == Mode.NON) { DllBox.MessageBox(IntPtr.Zero, "先选模式,臭嫑脸!~", "你干嘛", 0); return(true); } return(false); }
public void setNumber(string content) { Debug.Log(content); if (checkDataError()) { return; } int i; if (int.TryParse(content, out i)) { data.Number = i; } else { DllBox.MessageBox(IntPtr.Zero, "填正数", "佩奇", 0); } }
public void FindFileDir(int value) { if (checkDataError()) { return; } Text tt = null; OpenDialogDir ofn2 = new OpenDialogDir(); ofn2.pszDisplayName = new string(new char[2000]);; // 存放目录路径缓冲区 switch (value) { case 1: ofn2.dirTitle = "设置源目录"; tt = gameObject.transform.Find("BaseDirText").GetComponent <Text>(); break; case 2: ofn2.dirTitle = "设置目标目录"; tt = gameObject.transform.Find("TargetDirText").GetComponent <Text>(); break; case 3: ofn2.dirTitle = "设置索引目录"; tt = gameObject.transform.Find("LogText").GetComponent <Text>(); break; } //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框 IntPtr pidlPtr = DllBox.SHBrowseForFolder(ofn2); char[] charArray = new char[2000]; for (int i = 0; i < 2000; i++) { charArray[i] = '\0'; } DllBox.SHGetPathFromIDList(pidlPtr, charArray); string fullDirPath = new String(charArray); fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0')); Debug.Log(fullDirPath);//这个就是选择的目录路径。 if (tt == null) { return; } tt.text = fullDirPath; //for (int i = 20; i < tt.text.Length; i += 20) // tt.text = tt.text.Insert(i, "\n"); if (value == 1) { data.BaseDirPath = fullDirPath; } else if (value == 2) { data.TargetDirPath = fullDirPath; } else if (value == 3) { data.FolderPath = fullDirPath; } }
private IEnumerator FolderPick() { if (FolderItems.Values.Count <= 0) { DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0); yield return(null); } yield return(null); text.text = "开始执行"; foreach (GameObject obj in FolderItems.Values) { DataItem data = obj.GetComponent <ItemScript>().Data; if (!Directory.Exists(data.BaseDirPath) || !Directory.Exists(data.TargetDirPath) || !Directory.Exists(data.FolderPath)) { continue; } string[] baseNames = Directory.GetFiles(data.BaseDirPath); string[] targetNames = Directory.GetFiles(data.TargetDirPath); string[] FolderNames = Directory.GetFiles(data.FolderPath); if (!Directory.Exists(LogPath)) { Directory.CreateDirectory(LogPath); } FileStream fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now); sw.WriteLine("源目录" + data.BaseDirPath); sw.WriteLine("目标目录" + data.TargetDirPath); sw.WriteLine("索引目录" + data.FolderPath); sw.WriteLine("索引文件" + data.TxtPath); sw.WriteLine("移动张数" + data.Number); int count = 0; for (int i = 0; i < FolderNames.Length; i++) { if (targetNames.Contains(data.TargetDirPath + FolderNames[i].Replace(data.FolderPath, ""))) { sw.WriteLine("跳过文件" + FolderNames[i] + "目标已存在"); continue; } count++; if (count > data.Number) { break; } bool copy = false; for (int j = 0; j < baseNames.Length; j++) { if (baseNames[j].Equals(data.BaseDirPath + FolderNames[i].Replace(data.FolderPath, ""))) { copy = true; try { File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), false); sw.WriteLine("根据" + FolderNames[i] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath); text.text = "根据" + FolderNames[i] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath; } catch { sw.WriteLine("复制失败了" + baseNames[j]); text.text = "复制失败了" + baseNames[j]; copy = false; } yield return(new WaitForSeconds(0.05f)); } } if (!copy) { sw.WriteLine("失败了,没找到或不成功" + FolderNames[i]); } } sw.Close(); fs.Close(); } text.text = "执行完毕"; Debug.Log("running"); StopCoroutine("FolderPick"); }
private IEnumerator TxtPick() { if (TxtItems.Values.Count <= 0) { DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0); yield return(null); } text.text = "开始执行"; foreach (GameObject obj in TxtItems.Values) { DataItem data = obj.GetComponent <ItemScript>().Data; if (!Directory.Exists(data.BaseDirPath) || !Directory.Exists(data.TargetDirPath) || !File.Exists(data.TxtPath)) { continue; } string[] baseNames = Directory.GetFiles(data.BaseDirPath); string[] targetNames = Directory.GetFiles(data.TargetDirPath); FileStream txtfs = new FileStream(data.TxtPath, FileMode.Open); StreamReader sr = new StreamReader(txtfs); Queue <string> txtNames = new Queue <string>(); for (int c = 0; ; c++) { string s = sr.ReadLine(); txtNames.Enqueue(s.Split('#')[0]); if (sr.EndOfStream) { break; } } sr.Close(); txtfs.Close(); Debug.Log("zhixinglema " + txtNames.Count + "123"); if (!Directory.Exists(LogPath)) { Directory.CreateDirectory(LogPath); } FileStream fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now); sw.WriteLine("源目录" + data.BaseDirPath); sw.WriteLine("目标目录" + data.TargetDirPath); sw.WriteLine("索引目录" + data.FolderPath); sw.WriteLine("索引文件" + data.TxtPath); sw.WriteLine("移动张数" + data.Number); int count = 0; while (txtNames.Count > 0) { string txtname = txtNames.Dequeue(); if (targetNames.Contains(data.TargetDirPath + "\\" + txtname)) { sw.WriteLine("跳过文件" + txtname + "目标已存在"); continue; } count++; if (count > data.Number) { break; } bool copy = false; for (int j = 0; j < baseNames.Length; j++) { if (baseNames[j].Equals(data.BaseDirPath + "\\" + txtname)) { copy = true; try { File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), false); sw.WriteLine("根据" + txtname + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath); text.text = "根据" + txtname + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath + "移动了" + count + "张"; } catch { sw.WriteLine("复制失败了" + baseNames[j]); text.text = "复制失败了" + baseNames[j]; copy = false; } yield return(new WaitForSeconds(0.05f)); } } if (!copy) { sw.WriteLine("失败了,没找到或不成功" + txtname); } } sw.Close(); fs.Close(); } text.text = "执行完毕"; StopCoroutine("TxtPick"); }