IEnumerator WWWLoadLanguage() { yield return(null); string path = CDirectory.MakeCachePath(language); if (!File.Exists(path) || Application.isEditor) { using (var www = new WWW(CDirectory.MakeWWWStreamPath(language))) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { throw new Exception(string.Format("WWW download:" + www.error + " path : " + www.url)); } Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, www.bytes); } } byte[] bytes = File.ReadAllBytes(path); Localization.language = "language"; Localization.LoadCSV(bytes); LoadDll(); }
private IEnumerator LoadLevelBundle(string scene) { WWW www = new WWW(CDirectory.MakeFullWWWPath(string.Format("res/scenes/{0}.scene", scene))); while (!www.isDone) { progress = www.progress; yield return(null); } yield return(www); if (!string.IsNullOrEmpty(www.error)) { LOG.LogError("WWW download:" + www.error + " path : " + www.url); yield break; } if (www.isDone) { wwwProgress.Done(); isDone = true; SceneAB = www.assetBundle; www.Dispose(); if (AutoLoadScene) { CSceneManager.LoadSceneAsync(this.SceneName); } } }
protected IEnumerator LoadHotFixAysn() { Event.Trigger(CLuaEvents.ON_HOT_FIXED_START); string[] filePath = Config.Get <string[]>("lua.hotfix"); IResources resources = App.Make <IResources>(); foreach (string file in filePath) { FileInfo[] infos = CDirectory.Walk((CEnv.AssetPath + "/" + file)); foreach (var info in infos) { if (!info.Name.EndsWith(".manifest")) { yield return(resources.LoadAllAsyn <TextAsset>(file + "/" + info.Name, (textAssets) => { Event.Trigger(CLuaEvents.ON_HOT_FIXED_ACTION); foreach (TextAsset text in textAssets) { LuaEnv.DoString(text.text); } })); } } } Event.Trigger(CLuaEvents.ON_HOT_FIXED_END); Event.Trigger(CLuaEvents.ON_HOT_FIXED_COMPLETE); }
IEnumerator WWWLoadAssembly() { yield return(null); string path = CDirectory.MakeCachePath(_DllPath); if (!File.Exists(path)) { using (var www = new WWW(CDirectory.MakeWWWStreamPath(_DllPath))) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { throw new Exception(string.Format("WWW download:" + www.error + " path : " + www.url)); } Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, www.bytes); } } System.Reflection.Assembly assembly = null; #if ZTK assembly = ZToolKit.LoadAssembly(path); #else FileStream stream = File.Open(path, FileMode.Open); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); stream.Close(); assembly = System.Reflection.Assembly.Load(buffer); #endif this.game = (IGame)assembly.CreateInstance("CGame"); this.game.StartGame(); }
/// <summary> /// 保存图片 /// </summary> /// <param name="inputStream">输入数据流</param> /// <param name="sRootDirectory">保存的根目录(不要包括根据时间自动生成的目录)</param> /// <param name="sExtension">扩展名</param> /// <returns>返回根据时间自动生成的文件路径</returns> public static string SaveImage(Stream inputStream, string sRootDirectory, string sExtension) { sRootDirectory = sRootDirectory.TrimEnd('/', '\\'); string sReturn = GetImageDirectory() + CreateFileName(sExtension); string path = sRootDirectory + sReturn; CDirectory.Create(Path.GetDirectoryName(path)); using (FileStream fStream = File.Create(path)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = inputStream.Read(data, 0, data.Length); if (size > 0) { fStream.Write(data, 0, size); } else { break; } } } return(sReturn); }
protected IEnumerator UpdateAssetFromUrl(CUpdateList needUpdateLst, string downloadUrl) { updateNum = 0; needUpdateNum = needUpdateLst.Count(); string savePath, downloadPath, saveDir; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_START); foreach (CUpdateListField field in needUpdateLst) { downloadPath = downloadUrl + field.Path; savePath = CEnv.AssetPath + field.Path; saveDir = savePath.Substring(0, savePath.LastIndexOf('/')); updateNum++; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_ACTION); using (UnityWebRequest request = UnityWebRequest.Get(downloadPath)) { yield return(request.Send()); if (request.isError || request.responseCode != 200) { base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_FAILD); yield break; } CDirectory.CreateDir(saveDir); CFile.Cover(savePath, request.downloadHandler.data, 0, request.downloadHandler.data.Length); } } base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_END); }
public void Load() { loading = true; if (!string.IsNullOrEmpty(name) && name != "empty") { string path = string.Empty; path = CDirectory.MakeCachePath(name); if (!File.Exists(path)) { path = CDirectory.MakeOtherStreamingPath(name); } if (this.name.EndsWith(".txt")) { this.text = new StringBuilder(File.ReadAllText(path)); } else { this.asset_bundle = AssetBundle.CreateFromFile(path); } //this.complete = true; } if (!string.IsNullOrEmpty(name)) { this.complete = true; } }
/// <summary> /// 编译AssetBundle标记的名字 /// </summary> /// <param name="path">路径</param> protected static void BuildAssetBundleName(string path) { CDirectory.Walk(path, (file) => { if (!file.Name.EndsWith(".meta")) { CCreateAssetBundles.BuildFileBundleName(file, path); } }); }
public void Load() { loading = true; this.www = null; if (CMisc.isLegalNumber(name) && Global.publishConfig.isDebugOpen) { //CGameHintUI.Show(ErrorCodes.GetTextFormat(ErrorCodes.INVALID_LOAD_PATH, name)); return; } if (!string.IsNullOrEmpty(name) && name != "empty") { this.www = new WWW(CDirectory.MakeFullWWWPath(name)); } }
public bool CloneDirectoryTlock(int srcfsid, String sourcedir, int destfsid, String destinationdir) { string destdirpath = ExtractParentPath(destinationdir); if (destdirpath == null) { return(false); } Inode_Info destdiri = inode_exists_internal(destfsid, destdirpath, "dclone1", false, false); if (destdiri == null) { return(false); } Inode_Info destdiri2 = inode_exists_internal(destfsid, destinationdir, "dclone2", false, false); if (destdiri2 != null) { return(false); } Inode_Info srcdirA = inode_exists_internal(srcfsid, sourcedir, "dclone3", true, false); if (srcdirA == null) { return(false); } int count = srcdirA.nodecount; int pino = destdiri.ino; List <int> inolist = NEXT_N_INODE_NUMBERS(destfsid, count); CDirectory newdir = REDDY.FSIDList[srcfsid].rootdir.clone_directory_tlock(sourcedir, destfsid, inolist, pino, destdirpath); if (newdir == null) { return(false); } newdir.rename_directory(ADFN(destinationdir)); if (REDDY.FSIDList[destfsid].rootdir.insert_clonedirectory_tlock(destdirpath, newdir) == false) { //delete the wip. newdir.remove_orphan_directory(); return(false); } return(true); }
/// <summary> /// 编译列表文件 /// </summary> /// <param name="path">路径</param> protected static void BuildListFile(string path) { CUpdateList lst = new CUpdateList(path); CDirectory.Walk(path, (file) => { if (!file.Standard().EndsWith(".meta")) { string fullName = file.Standard(); string assetName = fullName.Substring(path.Length); lst.Append(assetName, CMD5.ParseFile(file), file.Length); } }); lst.Save(); }
/// <summary> /// 解压zip数据包并保存图片 /// </summary> /// <param name="inputStream">输入数据流</param> /// <param name="sDirectory">保存的根目录(不要包括根据时间自动生成的目录)</param> /// <returns>返回根据时间自动生成的文件路径列表</returns> public static List <string> UnzipImage(Stream inputStream, string sRootDirectory) { sRootDirectory = sRootDirectory.TrimEnd('/', '\\'); List <string> list = new List <string>(); using (ZipInputStream s = new ZipInputStream(inputStream)) { //为了防止图片文件名重复,在文件名后添加一个标识 int i = 0; ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(theEntry.Name); string fileName = Path.GetFileName(theEntry.Name); string extension = Path.GetExtension(theEntry.Name); if (fileName != string.Empty) { if (VaildImageType.IndexOf("/" + extension + "/") == -1) { continue; } string sReturn = GetImageDirectory() + CreateFileName(extension, i++); string path = sRootDirectory + @"\" + sReturn; CDirectory.Create(Path.GetDirectoryName(path)); using (FileStream fStream = File.Create(path)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { fStream.Write(data, 0, size); } else { break; } } } list.Add(sReturn); } } } return(list); }
/// <summary> /// 获取文件更新列表 /// </summary> /// <returns></returns> protected IEnumerator UpdateList(string resUrl) { base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_START); resUrl = resUrl + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); UnityWebRequest request = UnityWebRequest.Get(resUrl + "/" + CUpdateList.FILE_NAME); yield return(request.Send()); if (request.isError || request.responseCode != 200) { this.isUpdate = false; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_LIST_FAILED); yield break; } base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_START); var newLst = new CUpdateList(request).SetPath(CEnv.AssetPath); CUpdateList oldLst = new CUpdateList(CEnv.AssetPath); CDirectory.CreateDir(CEnv.AssetPath); CDirectory.Walk(CEnv.AssetPath, (file) => { if (!file.Standard().EndsWith(".meta")) { string fullName = file.Standard(); string assetName = fullName.Substring(CEnv.AssetPath.Length); oldLst.Append(assetName, CMD5.ParseFile(file), file.Length); } }); base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_END); CUpdateList needUpdateLst, needDeleteLst; oldLst.Comparison(newLst, out needUpdateLst, out needDeleteLst); yield return(this.DeleteOldAsset(needDeleteLst)); yield return(this.UpdateAssetFromUrl(needUpdateLst, resUrl)); newLst.Save(); base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_COMPLETE); }
public static void BuildAllAssetBundles() { RuntimePlatform switchPlatform = CEnv.SwitchPlatform; string platform = CEnv.PlatformToName(switchPlatform); CCreateAssetBundles.ClearAssetBundle(); CCreateAssetBundles.BuildAssetBundleName(CEnv.DataPath + CEnv.ResourcesBuildPath); string releasePath = CEnv.DataPath + CEnv.ReleasePath + "/" + platform; CDirectory.CreateDir(releasePath, CDirectory.Operations.EXISTS_TO_DELETE); BuildPipeline.BuildAssetBundles("Assets" + CEnv.ReleasePath + "/" + platform, BuildAssetBundleOptions.None, CCreateAssetBundles.PlatformToBuildTarget(switchPlatform)); CCreateAssetBundles.BuildListFile(releasePath); AssetDatabase.Refresh(); }
public void GenerateProject(CDBM db, string dir, string NamespaceName, string projectName, TextWriter mensajes) { CSharpProject p = new CSharpProject(projectName, dir); CDirectory baseDir = p.ActualDirectory; CUsing Namespace = new CUsing(NamespaceName); GenerateDef(db, p, NamespaceName, mensajes); p.AddChildDirectory(baseDir, "Poco"); CUsing NamespacePocos = new CUsing(NamespaceName + ".Poco"); GeneratePocos(db, p, NamespacePocos, mensajes); p.AddChildDirectory(baseDir, "Dao"); GenerateDaos(db, p, NamespaceName + ".Dao", NamespacePocos, mensajes); CUsing NamespaceDao = new CUsing(NamespaceName + ".Dao"); p.AddChildDirectory(baseDir, "Bo"); GenerateBo(db, p, NamespaceName + ".Bo", NamespacePocos, NamespaceDao, mensajes); p.Generate(mensajes); }
//--------------------------------------------------- static string GetAssemblyPath(out string mdb_path) { mdb_path = ""; string path = CDirectory.MakeFilePath(_DllPath); if (!Application.isMobilePlatform) { path = Application.dataPath + "/../Library/ScriptAssemblies/" + "Assembly-CSharp.dll"; if (File.Exists(path)) { mdb_path = Application.dataPath + "/../Library/ScriptAssemblies/" + "Assembly-CSharp.dll.mdb"; } else//client_build的路径 { path = CDirectory.MakeFilePath(_DllPath); mdb_path = CDirectory.MakeFilePath(_MDBPath); } } return(path); }
public ReMsg UploadPic(Stream stream) { string saveBase = SiteConfig.PhotoBasePath; var now = DateTime.Now; string fileUrl = string.Format("{0}/{1}/{2}/{3}/", saveBase, now.Year, now.Month, now.Day); string filePath = HttpContext.Current.Server.MapPath("~" + fileUrl); string fileName = DateTime.Now.ToString("hhmmss") + new Random().Next(1, 1000); string smallFileName = fileName + "_s"; fileName += ".jpg"; smallFileName += ".jpg"; CDirectory.Create(filePath); var fileFullName = Path.Combine(filePath, fileName); var smallFileFullName = Path.Combine(filePath, smallFileName); var fromimg = Image.FromStream(stream); bool b = false; try { b = MakeThumbnail(fromimg, fileFullName, fromimg.Width, fromimg.Height, 80); if (b) { b = MakeThumbnail(fromimg, smallFileFullName, 250, 250, 80); } } catch (Exception ex) { LogHelper.AddLog(ex.ToString()); } finally { if (fromimg != null) { fromimg.Dispose(); } } return(ReMsg(b, b ? fileUrl + fileName : "缩略图存储失败")); }
public static void SaveImage(Stream inputStream, string sFilePath) { CDirectory.Create(Path.GetDirectoryName(sFilePath)); using (FileStream fStream = File.Create(sFilePath)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = inputStream.Read(data, 0, data.Length); if (size > 0) { fStream.Write(data, 0, size); } else { break; } } } }
/// <summary> /// 保存缩略图片 /// </summary> /// <param name="inputStream">输入数据流</param> /// <param name="sRootDirectory">保存的根目录(不要包括根据时间自动生成的目录)</param> /// <param name="sExtension">扩展名</param> /// <param name="iWidth">图片宽度(缩略后)</param> /// <param name="iHeight">图片高度(缩略后)</param> /// <returns></returns> public static string SaveThumbnailImage(Stream inputStream, string sRootDirectory, string sExtension, int iWidth, int iHeight) { Image image = Image.FromStream(inputStream); image = image.GetThumbnailImage(iWidth, iHeight, null, System.IntPtr.Zero); MemoryStream newStream = new MemoryStream(); image.Save(newStream, GetImageType(sExtension)); newStream.Seek(0, SeekOrigin.Begin); //保存 sRootDirectory = sRootDirectory.TrimEnd('/', '\\'); string sReturn = GetImageDirectory() + "T" + CreateFileName(sExtension); string path = sRootDirectory + sReturn; CDirectory.Create(Path.GetDirectoryName(path)); using (FileStream fStream = File.Create(path)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = newStream.Read(data, 0, data.Length); if (size > 0) { fStream.Write(data, 0, size); } else { break; } } } return(sReturn); }
private void DumpToFile() { if (string.IsNullOrEmpty(filePath)) { if (!Directory.Exists(CDirectory.MakeCachePath("resdump"))) { Directory.CreateDirectory(CDirectory.MakeCachePath("resdump")); } filePath = CDirectory.MakeCachePath(string.Format("resdump/{0}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"))); } StreamWriter writer = File.AppendText(filePath); foreach (var c in factory.cookies.Values) { if (c.count == 0) { c.create_time = Time.realtimeSinceStartup; continue; } writer.WriteLine(c.ToLogString()); } writer.Close(); }
public static void archiveFolder( String rCloneDirectory, String localDropStream, String localArchiverBuffer, String remoteDropStreamTarget, String remoteArchive, String fileFormatNameRegex, String fileExtenstion, String thesholdInGigabytes) { Stopwatch watch = Stopwatch.StartNew(); String localTempFolder = String.Empty; String localZipDestination = String.Empty; try { ///Timer for diagnosing ///Let's get a temperary name for the temperary folder Logger.Info("Getting Temparary Folder... "); localTempFolder = Organizer.getTempFolderPath(localDropStream, localArchiverBuffer); Logger.Info(String.Format("{0} - {1}", "Temparary Folder Retrieved!", localTempFolder)); ///Where will this zip file be located locally Logger.Info("Creating Time-Stamped folders..."); localZipDestination = Organizer.createTimestampFolders(localDropStream, localArchiverBuffer, fileFormatNameRegex, fileExtenstion); Logger.Info(String.Format("{0}: {1}", "Time-Stamped folders created! Local Zip Destination", localZipDestination)); ///Compress / Remove the folder to be archived Logger.Info(String.Format("{0}: {1}", "Compress and removing target folder to the following location", localTempFolder)); Organizer.compressAndRemoveTargetFolder(localZipDestination); Logger.Info("Successfully compressed and removed folder!"); ///To make the threshold process a little easier, we need to rename any duplicated file names Logger.Info(String.Format("{0}: {1}", "Renaming any duplicated files for removal", localTempFolder)); CDirectory.renameDuplicatedFiles(rCloneDirectory, remoteArchive); Logger.Info("Duplicates renamed / removed!"); ///Serialize localzipdesitination file for parsing FileInfo info = new FileInfo(localZipDestination); ///Get a list of all of the existing files in target archive var existingFiles = CloudDirectory.serializeDirectory(CDirectory.getFilesStatsInDirectory(rCloneDirectory, remoteArchive)); ///Delete any files in cloud over threshold Logger.Info(String.Format("Removing any files over: {0} (GB) At remote Location: {1} Utilizing: {2}", thesholdInGigabytes, remoteArchive, info.Name)); List <FileCloudInfo> filesToRemove = Containment.getFIlesInDirectoryOverThreshold(existingFiles, info, Double.Parse(thesholdInGigabytes)); Logger.Info("Now removing a total of {0} files from cloud directory: {1}", filesToRemove.Count(), remoteArchive); Logger.Debug("Target Files: {0}", String.Concat(filesToRemove.Select(o => String.Format("\n{0} ", o.FilePath)))); //Print out all of the files to remove ///Run Command to Delete *any* target files filesToRemove.ForEach(i => CDelete.deleteDirectory(rCloneDirectory, String.Format(@"{0}/{1}", remoteArchive, i.FilePath))); ///Lots of logging, information regarding deleting items Logger.Info("Ran command to removed files over threshold! Files *removed*: {0} | Memory *Free'd up*: {1} (GB) ", filesToRemove.Count, ByteSizeLib.ByteSize.FromBytes(filesToRemove.Sum(i => i.Length)).GigaBytes, (filesToRemove.Sum(i => i.Length))); ///Moving Zipped file to the cloud storage Logger.Info(String.Format("{0} - Local Temp Folder: {1} RemoteArchive: {2}", "Moving the compressed file to cloud storage!", localTempFolder, remoteArchive)); CMove.moveFile(rCloneDirectory, localTempFolder, remoteArchive, Config.compressionFormat, Config.connectionAttempts); Logger.Info(String.Format("{0}", "Successfully deleted Contents!")); ///Delete the local folder Logger.Info(String.Format("{0}: {1}", "Deleting the following local 'Temp Folder' ", localTempFolder)); System.IO.Directory.Delete(localTempFolder, true); Logger.Info("Successfully deleted the local temp folder!"); ///TODO: Remove this to a later process... Logger.Info(String.Format("{0} - rCloneLocation: {1} gDriveName: {2}", "Deleting requested remote folders", rCloneDirectory, remoteDropStreamTarget)); CDelete.deleteDirectory(rCloneDirectory, remoteDropStreamTarget); Logger.Info(String.Format("{0}", "Deletion of contents command has been ran!")); ///Due to a bug, the cloud software may not "release" files. Resetting it will fix this. Logger.Info(String.Format("{0} - cloudProcessName: {1} cloudProcessPath: {2}", "Restarting Process", Config.cloudProcessName, Config.cloudProcessPath)); Management.restartProcess(Config.cloudProcessName, Config.cloudProcessPath); Logger.Info("Process successully restarted!"); ///Delete the cloud folder Logger.Info(String.Format("{0} - rCloneLocation: {1} gDriveName: {2}", "Emptying Cloud Folder", rCloneDirectory, Config.driveProfileName)); CDelete.emptyTrashFolder(rCloneDirectory, Config.driveProfileName); Logger.Info("Successfully emptied cloud recycle bin"); Logger.Info(String.Format("{0} - Elasped time:{1}", "Archiver has successully been ran!", watch.Elapsed.ToString())); } catch (OrganizerException e) { Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2} ", "Error while prepping files before transfer", e.Message, watch.Elapsed.ToString())); Logger.Trace(e.StackTrace); } catch (Rclone_Move_Exception e) { Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2}", "Error while transfering file to the cloud", e.Message, watch.Elapsed.ToString())); Logger.Trace(e.StackTrace); } catch (Exception e) { Logger.Error(e, String.Format("{0} - {1} (Elapsed time before error: {2} ", "Error while Archiving", e.Message, watch.Elapsed.ToString())); Logger.Trace(e.StackTrace); } finally { ///If the process fails, remove the temperary directory! if (Directory.Exists(localTempFolder)) { Directory.Delete(localTempFolder, true); } } }
public CDirectory AddChildDirectory(CDirectory baseDirectory, string directoryName) { return(this.ActualDirectory = baseDirectory.AddDirectory(directoryName)); }
public void SaveModel() { CDirectory.Create(FilePath); SerializeHelper <BaseXmlModel <T> > .SerToXml(_XmlModel, FullPath); }
public CSharpProject(string name, string directoryName) { this.Name = name; this.RootDirectory = new CDirectory(null, directoryName); }