void UPropertyConfigFileDisplayRow::InitWithConfigAndProperty(const FString& InConfigFileName, UProperty* InEditProperty) { ConfigFileName = FPaths::ConvertRelativePathToFull(InConfigFileName); ExternalProperty = InEditProperty; ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); // We will add source control soon... FSourceControlStatePtr SourceControlState = nullptr; // SourceControlProvider.GetState(ConfigFileName, EStateCacheUsage::Use); // Only include config files that are currently checked out or packages not under source control { if (FPaths::FileExists(ConfigFileName)) { if (SourceControlState.IsValid()) { bIsFileWritable = SourceControlState->IsCheckedOut() || SourceControlState->IsAdded(); } else { bIsFileWritable = !IFileManager::Get().IsReadOnly(*ConfigFileName); } } else { if (SourceControlState.IsValid()) { bIsFileWritable = (SourceControlState->IsSourceControlled() && SourceControlState->CanAdd()); } else { bIsFileWritable = false; } } } }
bool FGatherTextSCC::CheckOutFile(const FString& InFile, FText& OutError) { if ( InFile.IsEmpty() || InFile.StartsWith(TEXT("\\\\")) ) { OutError = NSLOCTEXT("GatherTextCmdlet", "InvalidFileSpecified", "Could not checkout file at invalid path."); return false; } FText SCCError; if( !IsReady( SCCError ) ) { OutError = SCCError; return false; } FString AbsoluteFilename = FPaths::ConvertRelativePathToFull( InFile ); if( CheckedOutFiles.Contains( AbsoluteFilename ) ) { return true; } bool bSuccessfullyCheckedOut = false; TArray<FString> FilesToBeCheckedOut; FilesToBeCheckedOut.Add( AbsoluteFilename ); FFormatNamedArguments Args; Args.Add(TEXT("Filepath"), FText::FromString(InFile)); ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider(); FSourceControlStatePtr SourceControlState = SourceControlProvider.GetState( AbsoluteFilename, EStateCacheUsage::ForceUpdate ); if(SourceControlState.IsValid()) { FString Other; if( SourceControlState->IsAdded() || SourceControlState->IsCheckedOut()) { // Already checked out or opened for add bSuccessfullyCheckedOut = true; } else if(SourceControlState->CanCheckout()) { bSuccessfullyCheckedOut = (SourceControlProvider.Execute( ISourceControlOperation::Create<FCheckOut>(), FilesToBeCheckedOut ) == ECommandResult::Succeeded); if (!bSuccessfullyCheckedOut) { OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "FailedToCheckOutFile", "Failed to check out file '{Filepath}'."), Args); } } else if(!SourceControlState->IsSourceControlled() && SourceControlState->CanAdd()) { bSuccessfullyCheckedOut = (SourceControlProvider.Execute( ISourceControlOperation::Create<FMarkForAdd>(), FilesToBeCheckedOut ) == ECommandResult::Succeeded); if (!bSuccessfullyCheckedOut) { OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "FailedToAddFileToSourceControl", "Failed to add file '{Filepath}' to source control."), Args); } } else if(!SourceControlState->IsCurrent()) { OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "FileIsNotAtHeadRevision", "File '{Filepath}' is not at head revision."), Args); } else if(SourceControlState->IsCheckedOutOther(&(Other))) { Args.Add(TEXT("Username"), FText::FromString(Other)); OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "FileIsAlreadyCheckedOutByAnotherUser", "File '{Filepath}' is checked out by another ('{Username}')."), Args); } else { // Improper or invalid SCC state OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "CouldNotGetStateOfFile", "Could not determine source control state of file '{Filepath}'."), Args); } } else { // Improper or invalid SCC state OutError = FText::Format(NSLOCTEXT("GatherTextCmdlet", "CouldNotGetStateOfFile", "Could not determine source control state of file '{Filepath}'."), Args); } if( bSuccessfullyCheckedOut ) { CheckedOutFiles.AddUnique(AbsoluteFilename); } return bSuccessfullyCheckedOut; }