private void TxtSearchUploadList_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { string key = txtSearchUploadList.Text.Trim(); listUploadList.SelectedIndex = -1; for (int i = indexSearchUploadList; i < listUploadList.Items.Count; i++) { AssetFileOperate file = listUploadList.Items[i] as AssetFileOperate; if (file.File?.Package?.IndexOf(key, StringComparison.CurrentCultureIgnoreCase) >= 0 || file.File?.ObjId?.IndexOf(key, StringComparison.CurrentCultureIgnoreCase) >= 0 || file.File?.FileId?.IndexOf(key, StringComparison.CurrentCultureIgnoreCase) >= 0 || file.File?.Name?.IndexOf(key, StringComparison.CurrentCultureIgnoreCase) >= 0) { indexSearchUploadList = i + 1; listUploadList.SelectedIndex = i; listUploadList.ScrollIntoView(file); return; } } //not found. start from begining next time. indexSearchUploadList = 0; } }
public string CheckForUpload() { if (IsMd5Checked == false) { return("请等待md5计算结束"); } UploadList.Clear(); //check files to upload, create upload task first. foreach (var item in LocalFiles) { var svrObj = cache.Parsed.GetNewestObjByPackageName(item.Package); //upload it if need. if (svrObj == null || //server no this file string.Compare(svrObj.fileAsset?.md5, item.Md5, true) != 0 || //or svr file is different string.IsNullOrEmpty(svrObj.fileAsset?.url) //or svr file download url is invalid. ) { AssetFileOperate op = new AssetFileOperate(); op.File = item; op.Operate = AssetFileOperateType.UploadFile; UploadList.Add(op); } } StringBuilder sb = new StringBuilder(); sb.AppendLine($"本地资源 {LocalFiles.Count}, 服务器资源 {cache.Parsed.PackageObjMap.Count}, 服务器对象 {ServerFiles.Count}"); foreach (var item in LocalFiles) { var assetFiles = cache.Parsed.GetFileAssetsByPackageName(item.Package); var objOnPackage = cache.Parsed.GetNewestObjByPackageName(item.Package); var productOnPackage = cache.Parsed.GetProductOnPackage(item.Package); ProductSpecModel specOnPackage = null; if (objOnPackage != null) { item.ObjId = objOnPackage.id; } if (productOnPackage?.specifications?.Count > 0 && string.IsNullOrEmpty(productOnPackage.specifications[0].id) == false) { specOnPackage = productOnPackage.specifications[0]; } if (objOnPackage == null) // server no this asset file, no staticmesh/material/texture/map. { if (item.IsInWorkDir == false) { continue;//only create objects for item in work dir. } localAdd.Add(item); AssetFileOperate op = new AssetFileOperate(); op.File = item; op.Operate = AssetFileOperateType.Create; //no file asset but exist a product to reference it. if (productOnPackage != null) { if (productOnPackage.specifications?.Count > 0 && string.IsNullOrEmpty(productOnPackage.specifications[0].id) == false) { op.Target = productOnPackage.specifications[0].id; op.specId = productOnPackage.specifications[0].id; op.spec = productOnPackage.specifications[0]; op.Operate = AssetFileOperateType.CreateAndUpdateSpec; } else { AssetFileOperate op2 = new AssetFileOperate(); op2.File = item; op2.Operate = AssetFileOperateType.DeleteProduct; op2.Target = productOnPackage.id; op2.productId = productOnPackage.id; UploadList.Add(op2); } } UploadList.Add(op); } else { //file asset existed. bool isFileChanged = string.Equals(objOnPackage.fileAsset?.md5, item.Md5, StringComparison.CurrentCultureIgnoreCase) == false; if (objOnPackage.IsDependenciesValid() == false) { isFileChanged = true;// force update invalid object. } if (isFileChanged) { //file changed. AssetFileOperate op = new AssetFileOperate(); op.File = item; op.Operate = AssetFileOperateType.Update; op.Target = objOnPackage.id; UploadList.Add(op); } } if (item.Class == "StaticMesh") { //product mising if (specOnPackage == null) { AssetFileOperate op = new AssetFileOperate(); op.File = item; op.Operate = AssetFileOperateType.CreateMissingProduct; UploadList.Add(op); } else // product exist. { string specmeshid = ""; if (specOnPackage.staticMeshes?.Count > 0) { specmeshid = specOnPackage.staticMeshes[0].id; } if (specOnPackage.ComponentsObj?.Count > 0) { foreach (var comp in specOnPackage.ComponentsObj) { var meshcomp = comp as FProductStaticMeshComponent; if (meshcomp?.StaticMesh != null) { specmeshid = meshcomp.StaticMesh.id; } } } //product do not use latest mesh if (string.Compare(objOnPackage.id, specmeshid, true) != 0) { AssetFileOperate op = new AssetFileOperate(); op.File = item; op.Operate = AssetFileOperateType.ProductUseLatestMesh; op.Target = specOnPackage.id; op.spec = specOnPackage; op.specId = specOnPackage.id; UploadList.Add(op); } } } //if item is static mesh } //foreach sb.AppendLine($"检测到改动 {UploadList.Count}"); IsCheckedForUpload = true; return(sb.ToString()); }