void FPathContextMenu::ExecuteSaveFolder() { // Get a list of package names in the selected paths TArray<FString> PackageNames; GetPackageNamesInSelectedPaths(PackageNames); // Form a list of packages from the assets TArray<UPackage*> Packages; for (int32 PackageIdx = 0; PackageIdx < PackageNames.Num(); ++PackageIdx) { UPackage* Package = FindPackage(NULL, *PackageNames[PackageIdx]); // Only save loaded and dirty packages if ( Package != NULL && Package->IsDirty() ) { Packages.Add(Package); } } // Save all packages that were found if ( Packages.Num() ) { ContentBrowserUtils::SavePackages(Packages); } }
void FNativeClassHierarchy::AddClassesForModule(const FName& InModuleName) { FAddClassMetrics AddClassMetrics; // Find the class package for this module UPackage* const ClassPackage = FindPackage(nullptr, *(FString("/Script/") + InModuleName.ToString())); if(!ClassPackage) { return; } TSet<FName> GameModules = GetGameModules(); TMap<FName, FName> PluginModules = GetPluginModules(); TArray<UObject*> PackageObjects; GetObjectsWithOuter(ClassPackage, PackageObjects, false); for(UObject* Object : PackageObjects) { UClass* const CurrentClass = Cast<UClass>(Object); if(CurrentClass) { AddClass(CurrentClass, GameModules, PluginModules, AddClassMetrics); } } UE_LOG(LogContentBrowser, Log, TEXT("Native class hierarchy updated for '%s' in %0.4f seconds. Added %d classes and %d folders."), *InModuleName.ToString(), FPlatformTime::Seconds() - AddClassMetrics.StartTime, AddClassMetrics.NumClassesAdded, AddClassMetrics.NumFoldersAdded); ClassHierarchyUpdatedDelegate.Broadcast(); }
bool FDeletePackageLatentCommand::Update() { UPackage* Package = FindPackage(NULL, *Parameter); if(Package != NULL) { TArray<UPackage*> Packages; Packages.Add(Package); if(PackageTools::UnloadPackages(Packages)) { FString PackageFileName = SourceControlHelpers::PackageFilename(Parameter); if(!FPlatformFileManager::Get().GetPlatformFile().DeleteFile(*PackageFileName)) { UE_LOG(LogSourceControl, Error, TEXT("Could not delete temporary package '%s'"), *PackageFileName); } } else { UE_LOG(LogSourceControl, Error, TEXT("Could not unload temporary package '%s'"), *Parameter); } } else { UE_LOG(LogSourceControl, Error, TEXT("Could not find temporary package '%s'"), *Parameter); } return true; }
/** * A utility function for looking up a package from an asset's full path (a * long package path). * * @param AssetPath The object path for a package that you want to look up. * @return A package containing the specified asset (NULL if the asset doesn't exist, or it isn't loaded). */ static UPackage* FindPackageForAsset(FString const& AssetPath) { FString PackagePath, AssetName; SplitPackagePathAndAssetName(AssetPath, PackagePath, AssetName); return FindPackage(NULL, *PackagePath); }
void FBlueprintRenameAndCloneTest::GetTests(TArray<FString>& OutBeautifiedNames, TArray<FString>& OutTestCommands) const { FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); TArray<FAssetData> ObjectList; AssetRegistryModule.Get().GetAssetsByClass(UBlueprint::StaticClass()->GetFName(), ObjectList); for (FAssetData const& Asset : ObjectList) { FString AssetObjPath = Asset.ObjectPath.ToString(); FString const Filename = FPackageName::LongPackageNameToFilename(AssetObjPath); if (!FAutomationTestFramework::GetInstance().ShouldTestContent(Filename)) { continue; } FString PackageName, AssetName; FBlueprintAutomationTestUtilities::SplitPackagePathAndAssetName(AssetObjPath, PackageName, AssetName); if (UPackage* ExistingPackage = FindPackage(NULL, *PackageName)) { if (ExistingPackage->HasAnyFlags(RF_RootSet)) { continue; } } OutBeautifiedNames.Add(Asset.AssetName.ToString()); OutTestCommands.Add(AssetObjPath); } }
void FPathContextMenu::ExecuteSCCSync() const { ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); TArray<FString> RootPaths; FPackageName::QueryRootContentPaths( RootPaths ); // find valid paths on disk TArray<FString> PathsOnDisk; for(const auto& SelectedPath : SelectedPaths) { // note: we make sure to terminate our path here so root directories map correctly. const FString CompletePath = SelectedPath / ""; const bool bMatchesRoot = RootPaths.ContainsByPredicate([&](const FString& RootPath){ return CompletePath.StartsWith(RootPath); }); if(bMatchesRoot) { FString PathOnDisk = FPackageName::LongPackageNameToFilename(CompletePath); PathsOnDisk.Add(PathOnDisk); } } if ( PathsOnDisk.Num() > 0 ) { // attempt to unload all assets under this path TArray<FString> PackageNames; GetPackageNamesInSelectedPaths(PackageNames); // Form a list of loaded packages to prompt for save TArray<UPackage*> LoadedPackages; for( const auto& PackageName : PackageNames ) { UPackage* Package = FindPackage(nullptr, *PackageName); if ( Package != nullptr ) { LoadedPackages.Add(Package); } } FText ErrorMessage; PackageTools::UnloadPackages(LoadedPackages, ErrorMessage); if(!ErrorMessage.IsEmpty()) { FMessageDialog::Open( EAppMsgType::Ok, ErrorMessage ); } else { SourceControlProvider.Execute(ISourceControlOperation::Create<FSync>(), PathsOnDisk); } } else { UE_LOG(LogContentBrowser, Warning, TEXT("Couldn't find any valid paths to sync.")) } }
void FPathContextMenu::ExecuteSCCOpenForAdd() { ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); // Get a list of package names in the selected paths TArray<FString> PackageNames; GetPackageNamesInSelectedPaths(PackageNames); TArray<FString> PackagesToAdd; TArray<UPackage*> PackagesToSave; for ( auto PackageIt = PackageNames.CreateConstIterator(); PackageIt; ++PackageIt ) { FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState(SourceControlHelpers::PackageFilename(*PackageIt), EStateCacheUsage::Use); if ( SourceControlState.IsValid() && !SourceControlState->IsSourceControlled() ) { PackagesToAdd.Add(*PackageIt); // Make sure the file actually exists on disk before adding it FString Filename; if ( !FPackageName::DoesPackageExist(*PackageIt, NULL, &Filename) ) { UPackage* Package = FindPackage(NULL, **PackageIt); if ( Package ) { PackagesToSave.Add(Package); } } } } if ( PackagesToAdd.Num() > 0 ) { // If any of the packages are new, save them now if ( PackagesToSave.Num() > 0 ) { const bool bCheckDirty = false; const bool bPromptToSave = false; TArray<UPackage*> FailedPackages; const FEditorFileUtils::EPromptReturnCode Return = FEditorFileUtils::PromptForCheckoutAndSave(PackagesToSave, bCheckDirty, bPromptToSave, &FailedPackages); if(FailedPackages.Num() > 0) { // don't try and add files that failed to save - remove them from the list for(auto FailedPackageIt = FailedPackages.CreateConstIterator(); FailedPackageIt; FailedPackageIt++) { PackagesToAdd.Remove((*FailedPackageIt)->GetName()); } } } if ( PackagesToAdd.Num() > 0 ) { SourceControlProvider.Execute(ISourceControlOperation::Create<FMarkForAdd>(), SourceControlHelpers::PackageFilenames(PackagesToAdd)); } } }
void FAssetFixUpRedirectors::LoadReferencingPackages(TArray<FRedirectorRefs>& RedirectorsToFix, TArray<UPackage*>& OutReferencingPackagesToSave) const { FScopedSlowTask SlowTask( RedirectorsToFix.Num(), LOCTEXT( "LoadingReferencingPackages", "Loading Referencing Packages..." ) ); SlowTask.MakeDialog(); ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); // Load all packages that reference each redirector, if possible for ( auto RedirectorRefsIt = RedirectorsToFix.CreateIterator(); RedirectorRefsIt; ++RedirectorRefsIt ) { SlowTask.EnterProgressFrame(1); FRedirectorRefs& RedirectorRefs = *RedirectorRefsIt; if ( ISourceControlModule::Get().IsEnabled() ) { FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState(RedirectorRefs.Redirector->GetOutermost(), EStateCacheUsage::Use); const bool bValidSCCState = !SourceControlState.IsValid() || SourceControlState->IsAdded() || SourceControlState->IsCheckedOut() || SourceControlState->CanCheckout() || !SourceControlState->IsSourceControlled() || SourceControlState->IsIgnored(); if ( !bValidSCCState ) { RedirectorRefs.bRedirectorValidForFixup = false; RedirectorRefs.FailureReason = LOCTEXT("RedirectorFixupFailed_BadSCC", "Redirector could not be checked out or marked for delete"); } } // Load all referencers for ( auto PackageNameIt = RedirectorRefs.ReferencingPackageNames.CreateConstIterator(); PackageNameIt; ++PackageNameIt ) { const FString PackageName = (*PackageNameIt).ToString(); // Find the package in memory. If it is not in memory, try to load it UPackage* Package = FindPackage(NULL, *PackageName); if ( !Package ) { Package = LoadPackage(NULL, *PackageName, LOAD_None); } if ( Package ) { if ( Package->PackageFlags & PKG_CompiledIn ) { // This is a script reference RedirectorRefs.bRedirectorValidForFixup = false; RedirectorRefs.FailureReason = FText::Format(LOCTEXT("RedirectorFixupFailed_CodeReference", "Redirector is referenced by code. Package: {0}"), FText::FromString(PackageName)); } else { // If we found a valid package, mark it for save OutReferencingPackagesToSave.AddUnique(Package); } } } } }
bool FFrontendFilter_Modified::PassesFilter(FAssetFilterType InItem) const { UPackage* Package = FindPackage(NULL, *InItem.PackageName.ToString()); if ( Package != NULL ) { return Package->IsDirty(); } return false; }
void FAssetContextMenu::GetSelectedPackages(TArray<UPackage*>& OutPackages) const { for (int32 AssetIdx = 0; AssetIdx < SelectedAssets.Num(); ++AssetIdx) { UPackage* Package = FindPackage(NULL, *SelectedAssets[AssetIdx].PackageName.ToString()); if ( Package ) { OutPackages.Add(Package); } } }
UClass* FClassBrowseHelper::FindAssetClass(const FString& GeneratedClassPackage, const FString& AssetName) { UPackage* Package = FindPackage(NULL, *GeneratedClassPackage ); if (Package) { UObject* Object = FindObject<UObject>(Package, *AssetName); if (Object) { UBlueprint* BlueprintOb = Cast<UBlueprint>(Object); return BlueprintOb ? *BlueprintOb->GeneratedClass : Object->GetClass(); } } return NULL; }
void FPathContextMenu::ExecuteSCCCheckIn() { // Get a list of package names in the selected paths TArray<FString> PackageNames; GetPackageNamesInSelectedPaths(PackageNames); // Form a list of loaded packages to prompt for save TArray<UPackage*> LoadedPackages; for ( auto PackageIt = PackageNames.CreateConstIterator(); PackageIt; ++PackageIt ) { UPackage* Package = FindPackage(NULL, **PackageIt); if ( Package ) { LoadedPackages.Add(Package); } } // Prompt the user to ask if they would like to first save any dirty packages they are trying to check-in const FEditorFileUtils::EPromptReturnCode UserResponse = FEditorFileUtils::PromptForCheckoutAndSave( LoadedPackages, true, true ); // If the user elected to save dirty packages, but one or more of the packages failed to save properly OR if the user // canceled out of the prompt, don't follow through on the check-in process const bool bShouldProceed = ( UserResponse == FEditorFileUtils::EPromptReturnCode::PR_Success || UserResponse == FEditorFileUtils::EPromptReturnCode::PR_Declined ); if ( bShouldProceed ) { TArray<FString> PendingDeletePaths; for (const auto& Path : SelectedPaths) { PendingDeletePaths.Add(FPaths::ConvertRelativePathToFull(FPackageName::LongPackageNameToFilename(Path + TEXT("/")))); } const bool bUseSourceControlStateCache = false; FSourceControlWindows::PromptForCheckin(bUseSourceControlStateCache, PackageNames, PendingDeletePaths); } else { // If a failure occurred, alert the user that the check-in was aborted. This warning shouldn't be necessary if the user cancelled // from the dialog, because they obviously intended to cancel the whole operation. if ( UserResponse == FEditorFileUtils::EPromptReturnCode::PR_Failure ) { FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "SCC_Checkin_Aborted", "Check-in aborted as a result of save failure.") ); } } }
void FLevelCollectionModel::SCCOpenForAdd(const FLevelModelList& InList) { ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); TArray<FString> FilenamesList = GetFilenamesList(InList); TArray<FString> FilenamesToAdd; TArray<UPackage*> PackagesToSave; for (auto It = FilenamesList.CreateConstIterator(); It; ++It) { const FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState(*It, EStateCacheUsage::Use); if (SourceControlState.IsValid() && !SourceControlState->IsSourceControlled()) { FilenamesToAdd.Add(*It); // Make sure the file actually exists on disk before adding it FString LongPackageName = FPackageName::FilenameToLongPackageName(*It); if (!FPackageName::DoesPackageExist(LongPackageName)) { UPackage* Package = FindPackage(NULL, *LongPackageName); if (Package) { PackagesToSave.Add(Package); } } } } if (FilenamesToAdd.Num() > 0) { // If any of the packages are new, save them now if (PackagesToSave.Num() > 0) { const bool bCheckDirty = false; const bool bPromptToSave = false; const auto Return = FEditorFileUtils::PromptForCheckoutAndSave(PackagesToSave, bCheckDirty, bPromptToSave); } SourceControlProvider.Execute(ISourceControlOperation::Create<FMarkForAdd>(), FilenamesToAdd); } }
bool EngineUtils::FindOrLoadAssetsByPath(const FString& Path, TArray<UObject*>& OutAssets) { if ( !FPackageName::IsValidLongPackageName(Path, true) ) { return false; } // Convert the package path to a filename with no extension (directory) const FString FilePath = FPackageName::LongPackageNameToFilename(Path); // Gather the package files in that directory and subdirectories TArray<FString> Filenames; FPackageName::FindPackagesInDirectory(Filenames, FilePath); // Cull out map files for (int32 FilenameIdx = Filenames.Num() - 1; FilenameIdx >= 0; --FilenameIdx) { const FString Extension = FPaths::GetExtension(Filenames[FilenameIdx], true); if ( Extension == FPackageName::GetMapPackageExtension() ) { Filenames.RemoveAt(FilenameIdx); } } // Load packages or find existing ones and fully load them TSet<UPackage*> Packages; for (int32 FileIdx = 0; FileIdx < Filenames.Num(); ++FileIdx) { const FString& Filename = Filenames[FileIdx]; UPackage* Package = FindPackage(NULL, *FPackageName::FilenameToLongPackageName(Filename)); if (Package) { Package->FullyLoad(); } else { Package = LoadPackage(NULL, *Filename, LOAD_None); } if (Package) { Packages.Add(Package); } } // If any packages were successfully loaded, find all assets that were in the packages and add them to OutAssets if ( Packages.Num() > 0 ) { for (FObjectIterator ObjIt; ObjIt; ++ObjIt) { if ( Packages.Contains(ObjIt->GetOutermost()) && ObjIt->IsAsset() ) { OutAssets.Add(*ObjIt); } } } return true; }
UFunction* UTimelineComponent::GetTimelineLinearColorSignature() { UFunction* TimelineVectorSig = FindObject<UFunction>(FindPackage(nullptr, TEXT("/Script/Engine")), TEXT("OnTimelineLinearColor__DelegateSignature")); check(TimelineVectorSig != NULL); return TimelineVectorSig; }