public static async Task Convert_To_Wav(string From_Dir, string To_Dir, bool IsFromFileDelete) { try { if (!Directory.Exists(To_Dir)) { Directory.CreateDirectory(To_Dir); } From_Files.Clear(); string[] Ex = new string[] { ".mp3", ".aac", ".ogg", ".flac", ".wma", ".wav" }; From_Files.AddRange(DirectoryEx.GetFiles(From_Dir, SearchOption.TopDirectoryOnly, Ex)); var tasks = new List <Task>(); for (int i = 0; i < From_Files.Count; i++) { tasks.Add(To_WAV(i, To_Dir, IsFromFileDelete)); } await Task.WhenAll(tasks); From_Files.Clear(); } catch (Exception ex) { From_Files.Clear(); Sub_Code.Error_Log_Write(ex.Message); } }
private static IEnumerable <Process> GetInstances() { if (Attributes.AppWaitFull < 0) { return(ProcessEx.GetInstances(Attributes.AppPath, true)); } if (_instanceDirs == default(List <string>)) { _instanceDirs = new List <string>(); switch (Attributes.AppWaitFull) { case 0: case 1: _instanceDirs.Add(Attributes.AppDir); _instanceDirs.Add(Attributes.DataDir); break; default: _instanceDirs.Add(PathEx.LocalDir); if (Attributes.DirMap?.Any() == true) { var fromKeys = Attributes.DirMap.Keys.Where(x => !x.StartsWithEx(PathEx.LocalDir)).ToArray(); if (fromKeys.Any()) { _instanceDirs.AddRange(fromKeys); } var fromValues = Attributes.DirMap.Values.Where(x => !x.StartsWithEx(PathEx.LocalDir)).ToArray(); if (fromValues.Any()) { _instanceDirs.AddRange(fromValues); } } break; } if (Attributes.AppWaitDirs?.Any() == true) { _instanceDirs.AddRange(Attributes.AppWaitDirs); } _instanceDirs = _instanceDirs.Select(PathEx.Combine).Distinct().ToList(); } var files = new List <string>(); foreach (var dir in _instanceDirs.Where(Directory.Exists)) { files.AddRange(DirectoryEx.GetFiles(dir, "*.exe", SearchOption.AllDirectories).Where(x => !x.EqualsEx(PathEx.LocalPath))); } files = (Attributes.IgnoredProcesses?.Any() == true ? files.Distinct().Where(x => !Attributes.IgnoredProcesses.ContainsEx(Path.GetFileName(x), Path.GetFileNameWithoutExtension(x))) : files.Distinct()).ToList(); return(files.SelectMany(x => ProcessEx.GetInstances(Attributes.AppWaitFull == 0 ? Path.GetFileName(x) : x, Attributes.AppWaitFull >= 2)).Distinct().Where(x => x.Handle != ProcessEx.CurrentHandle)); }
/// <summary>获取所有缓存文件的大小,单位字节</summary> public long Length() { long capacity = 0; FileInfo[] filesArr = DirectoryEx.GetFiles(CacheDefine.CachePath); for (int i = 0; i < filesArr.Length; i++) { FileInfo fileInfo = filesArr[i]; capacity += fileInfo.Length; } return(capacity); }
//[MenuItem("MXFramework/AssetBundle/Set AssetBundle Label", false, 201)] public static void SetAbLabel() { string abFolder = AssetDefine.GetABResourcePath(); if (!Directory.Exists(abFolder)) { Directory.CreateDirectory(abFolder); } FileInfo[] files = DirectoryEx.GetFiles(abFolder, Filter); foreach (FileInfo fileInfo in files) { SetFileABLabel(fileInfo); } //清空无用AB标记 AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh();//刷新 Debug.Log("自动设置标志完成!"); }
public static IEnumerable <string> GetFiles(string path) { var queue = new Queue <string>(); queue.Enqueue(path); string[] tmp; while (queue.Count > 0) { path = queue.Dequeue(); try { tmp = DirectoryEx.GetFiles(path); } catch (Exception ex) { Console.WriteLine(ex.ToString()); continue; } foreach (var t in tmp) { yield return(t); } try { tmp = DirectoryEx.GetDirectories(path); } catch (Exception ex) { Console.WriteLine(ex.ToString()); continue; } foreach (var subDir in tmp) { queue.Enqueue(subDir); } } }
public static async Task Convert_To_Wav(string From_Dir, string To_Dir, bool IsFromFileDelete, bool IsUseFFmpeg = false, bool BassEncode = false, bool NoWAVFileMode = true) { try { if (!Directory.Exists(To_Dir)) { Directory.CreateDirectory(To_Dir); } From_Files.Clear(); string[] Ex; if (IsUseFFmpeg || !NoWAVFileMode) { Ex = new string[] { ".mp3", ".aac", ".ogg", ".flac", ".wma", ".wav" } } ; else { Ex = new string[] { ".mp3", ".aac", ".ogg", ".flac", ".wma" } }; From_Files.AddRange(DirectoryEx.GetFiles(From_Dir, SearchOption.TopDirectoryOnly, Ex)); var tasks = new List <Task>(); for (int i = 0; i < From_Files.Count; i++) { if (Sub_Code.Audio_IsWAV(From_Files[i]) && NoWAVFileMode) { continue; } tasks.Add(To_WAV(i, To_Dir, IsFromFileDelete, IsUseFFmpeg, BassEncode)); } await Task.WhenAll(tasks); } catch (Exception ex) { Sub_Code.Error_Log_Write(ex.Message); } From_Files.Clear(); }
private static void UpdateAppInfoFile() { ResetAppInfoFile(); if (_appInfo?.Count > 430) { goto Shareware; } foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal)) { var link = PathEx.AltCombine(mirror, ".free", "AppInfo.ini"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal)) { NetEx.Transfer.DownloadFile(link, CachePaths.AppInfo, 60000, UserAgents.Internal, false); } if (!File.Exists(CachePaths.AppInfo)) { continue; } break; } var blacklist = Array.Empty <string>(); if (File.Exists(CachePaths.AppInfo)) { blacklist = Ini.GetSections(CachePaths.AppInfo).Where(x => Ini.Read(x, "Disabled", false, CachePaths.AppInfo)).ToArray(); UpdateAppInfoData(CachePaths.AppInfo, blacklist); } var tmpDir = Path.Combine(CorePaths.TempDir, PathEx.GetTempDirName()); if (!DirectoryEx.Create(tmpDir)) { return; } var tmpZip = Path.Combine(tmpDir, "AppInfo.7z"); foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal)) { var link = PathEx.AltCombine(mirror, ".free", "AppInfo.7z"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal)) { NetEx.Transfer.DownloadFile(link, tmpZip, 60000, UserAgents.Internal, false); } if (!File.Exists(tmpZip)) { continue; } break; } if (!File.Exists(tmpZip)) { var link = PathEx.AltCombine(AppSupplierHosts.PortableApps, "updater", "update.7z"); if (Log.DebugMode > 0) { Log.Write($"Cache: Looking for '{link}'."); } if (NetEx.FileIsAvailable(link, 60000, UserAgents.Empty)) { NetEx.Transfer.DownloadFile(link, tmpZip, 60000, UserAgents.Empty, false); } } if (File.Exists(tmpZip)) { using (var process = Compaction.SevenZipHelper.Unzip(tmpZip, tmpDir)) if (process?.HasExited == false) { process.WaitForExit(); } FileEx.TryDelete(tmpZip); } var tmpIni = DirectoryEx.GetFiles(tmpDir, "*.ini").FirstOrDefault(); if (!File.Exists(tmpIni)) { DirectoryEx.TryDelete(tmpDir); return; } UpdateAppInfoData(tmpIni, blacklist); FileEx.Serialize(CachePaths.AppInfo, AppInfo, true); DirectoryEx.TryDelete(tmpDir); Shareware: if (!Shareware.Enabled) { return; } foreach (var srv in Shareware.GetAddresses()) { var key = Shareware.FindAddressKey(srv); var usr = Shareware.GetUser(srv); var pwd = Shareware.GetPassword(srv); var url = PathEx.AltCombine(srv, "AppInfo.ini"); if (Log.DebugMode > 0) { Log.Write($"Shareware: Looking for '{{{key.Encode()}}}/AppInfo.ini'."); } if (!NetEx.FileIsAvailable(url, usr, pwd, 60000, UserAgents.Default)) { continue; } var appInfo = NetEx.Transfer.DownloadString(url, usr, pwd, 60000, UserAgents.Default); if (string.IsNullOrWhiteSpace(appInfo)) { continue; } UpdateAppInfoData(appInfo, null, key.Decode(BinaryToTextEncodings.Base85)); } }
public static List <string> playlists() { return(DirectoryEx.GetFiles(Resource.PersonalLevelPlaylistsDirPath_).ToList()); }
//新サウンドエンジンでは曲が終わったら次の曲を流すということができないため、ランダムで曲をつなげて5分以上にします //戦闘時間は7分なので7分30秒以降はカットされます public static void Set_Music_Mix_Random(string BGM_Dir, int Max_Second = 440) { try { Random r = new Random(); string[] Ex = { ".mp3", ".mp2", ".wav", ".ogg", "aiff", ".aif", ".asf", ".flac", ".wma" }; string[] BGM_Files_Temp = DirectoryEx.GetFiles(BGM_Dir, SearchOption.TopDirectoryOnly, Ex); Directory.CreateDirectory(WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/BGM_Temp"); foreach (string BGM_File_Now in BGM_Files_Temp) { File.Copy(BGM_File_Now, WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/BGM_Temp/" + Path.GetFileName(BGM_File_Now), true); } string[] BGM_Files = DirectoryEx.GetFiles(WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/BGM_Temp", SearchOption.TopDirectoryOnly, Ex); int File_Number_Now = -1; foreach (string BGM_File_Now in BGM_Files) { File_Number_Now++; int stream = Bass.BASS_StreamCreateFile(BGM_File_Now, 0, 0, BASSFlag.BASS_STREAM_DECODE); int length = (int)Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)); Bass.BASS_StreamFree(stream); if (length >= 300) { continue; } List <int> Include_Numbers = new List <int>(); Include_Numbers.Add(File_Number_Now); for (int Number = 0; Number < BGM_Files.Length; Number++) { if (Include_Numbers.Count >= BGM_Files.Length) { Include_Numbers.Clear(); Number = -1; continue; } int Include_Number = 0; while (true) { int Temp = r.Next(0, BGM_Files.Length); bool IsIncluded = false; foreach (int Number_Now in Include_Numbers) { if (Number_Now == Temp) { IsIncluded = true; break; } } if (!IsIncluded) { Include_Number = Temp; break; } } Include_Numbers.Add(Include_Number); int stream2 = Bass.BASS_StreamCreateFile(BGM_Files[Include_Number], 0, 0, BASSFlag.BASS_STREAM_DECODE); int length2 = (int)Bass.BASS_ChannelBytes2Seconds(stream2, Bass.BASS_ChannelGetLength(stream2)); Bass.BASS_StreamFree(stream2); length += length2; if (length >= 300) { break; } } StreamWriter stw = File.CreateText(WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/Encode_Mp3/BGM_Mix.bat"); stw.WriteLine("chcp 65001"); stw.Write("\"" + WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/Encode_Mp3/ffmpeg.exe\" -y "); foreach (int Number in Include_Numbers) { stw.Write("-i \"" + BGM_Files[Number] + "\" "); } stw.Write("-filter_complex \"concat=n=" + Include_Numbers.Count + ":v=0:a=1\" -t " + Max_Second + " \"" + BGM_Dir + "/" + Path.GetFileName(BGM_Files[File_Number_Now]) + "\""); stw.Close(); ProcessStartInfo processStartInfo1 = new ProcessStartInfo { FileName = WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/Encode_Mp3/BGM_Mix.bat", CreateNoWindow = true, UseShellExecute = false }; Process p = Process.Start(processStartInfo1); p.WaitForExit(); File.Delete(WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/Encode_Mp3/BGM_Mix.bat"); } Directory.Delete(WoTB_Voice_Mod_Creater.Voice_Set.Special_Path + "/BGM_Temp", true); } catch (Exception e) { WoTB_Voice_Mod_Creater.Sub_Code.Error_Log_Write(e.Message); } }