Skip to content

Commit

Permalink
fix guards
Browse files Browse the repository at this point in the history
  • Loading branch information
czoido committed Jun 20, 2024
1 parent bdd0a47 commit 5c8bb21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
20 changes: 9 additions & 11 deletions ConanFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class ConanFileManager
"# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements"
};

private static bool IsFileCommentGuarded(string path)
public static bool IsFileCommentGuarded(string path)
{
if (!File.Exists(path)) return false;

Expand Down Expand Up @@ -54,10 +54,10 @@ public static string[] GetConandataRequirements(string projectDirectory)
return new string[] { };
}

private static void WriteConanfileIfNecessary(string projectDirectory)
public static bool ReCreateConanfile(string projectDirectory)
{
string conanfilePath = Path.Combine(projectDirectory, "conanfile.py");
if (!IsFileCommentGuarded(conanfilePath))
if (IsFileCommentGuarded(conanfilePath) || !File.Exists(conanfilePath))
{
string conanfileContents = string.Join(Environment.NewLine,
_modifyCommentGuard.Concat(new string[]
Expand All @@ -84,26 +84,24 @@ private static void WriteConanfileIfNecessary(string projectDirectory)
);

File.WriteAllText(conanfilePath, conanfileContents);
return true;
}
return false;
}

private static void WriteConandataIfNecessary(string projectDirectory)
public static bool ReCreateConanData(string projectDirectory)
{
string conandataPath = Path.Combine(projectDirectory, "conandata.yml");
if (!IsFileCommentGuarded(conandataPath))
if (IsFileCommentGuarded(conandataPath) || !File.Exists(conandataPath))
{
string conandataContents = string.Join(Environment.NewLine,
_modifyCommentGuard.Concat(new string[] { "requirements:" })
);

File.WriteAllText(conandataPath, conandataContents);
return true;
}
}

public static void WriteNecessaryConanGuardedFiles(string projectDirectory)
{
WriteConanfileIfNecessary(projectDirectory);
WriteConandataIfNecessary(projectDirectory);
return false;
}

public static void WriteNewRequirement(string projectDirectory, string newRequirement)
Expand Down
13 changes: 11 additions & 2 deletions ConanToolWindowControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,17 @@ private void InstallButton_Click(object sender, RoutedEventArgs e)
string projectFilePath = startupProject.FullName;
string projectDirectory = Path.GetDirectoryName(projectFilePath);

ConanFileManager.WriteNecessaryConanGuardedFiles(projectDirectory);
ConanFileManager.WriteNewRequirement(projectDirectory, selectedLibrary + "/" + selectedVersion);
ConanFileManager.ReCreateConanfile(projectDirectory);

string conandataPath = Path.Combine(projectDirectory, "conandata.yml");

if (!File.Exists(conandataPath)) {
ConanFileManager.ReCreateConanData(projectDirectory);
}

if (ConanFileManager.IsFileCommentGuarded(conandataPath)) {
ConanFileManager.WriteNewRequirement(projectDirectory, selectedLibrary + "/" + selectedVersion);
}

_ = ProjectConfigurationManager.SaveConanPrebuildEventsAllConfigAsync(startupProject);
VersionsComboBox.IsEnabled = false;
Expand Down

0 comments on commit 5c8bb21

Please sign in to comment.