public static void CleanAll(Log log, IEnumerable <string> files) { try { foreach (var file in files) { try { var parentDirectory = Path.GetDirectoryName(file); Disk.DeleteDirectory(log, Path.Combine(parentDirectory, ".uno", "stuff")); foreach (var item in StuffObject.Load(file, StuffFlags.AcceptAll)) { Disk.DeleteDirectory(log, Path.Combine( parentDirectory, item.Key.Replace('/', Path.DirectorySeparatorChar))); } } catch (Exception e) { log.Error(file.ToRelativePath() + ": " + e.Message); } } } finally { DownloadCache.AutoCollect(log); } }
bool Install() { try { foreach (var item in StuffObject.Load(_stuffFile, _flags, _optionalVars)) { _tasks.Add(Task.Factory.StartNew( () => { try { InstallItem(item); } catch (Exception e) { Log.Error(_stuffFile.ToRelativePath() + " (" + item.Key + "): " + e.Message); _retval = false; } })); } } catch (Exception e) { throw new Exception(_stuffFile.ToRelativePath() + ": " + e.Message, e); } Task.WaitAll(_tasks.ToArray()); return(_retval); }
public int Load() { var stuff = StuffObject.Load(FullName); stuff.TryGetValue("$", out int hash); stuff.TryGetValue(nameof(UnoVersion), out UnoVersion); stuff.TryGetValue(nameof(BuildCommand), out BuildCommand); stuff.TryGetValue(nameof(RunCommand), out RunCommand); stuff.TryGetValue(nameof(Product), out Product); return(hash); }
void SkipStuff(string fullName) { var parentDir = Path.GetDirectoryName(fullName); // Ignore directories listed in *.stuff files foreach (var e in StuffObject.Load(fullName, StuffFlags.AcceptAll)) { var stuffPath = Path.Combine(parentDir, e.Key.UnixToNative()); _log.Event(IOEvent.Ignore, stuffPath, "stuff directory"); SkipFile(stuffPath); } }
PackageFile(StuffObject stuff, string dir) : this(dir) { stuff.TryGetValue(nameof(BuildCondition), out BuildCondition); stuff.TryGetValue(nameof(SourceDirectory), out SourceDirectory); stuff.TryGetValue(nameof(IsTransitive), out IsTransitive); References.AddRange(stuff.GetArray(nameof(References), PackageReference.FromString)); InternalsVisibleTo.AddRange(stuff.GetArray(nameof(InternalsVisibleTo))); SourceFiles.AddRange(stuff.GetArray(nameof(SourceFiles), FileItem.FromString)); ExtensionsFiles.AddRange(stuff.GetArray(nameof(ExtensionsFiles), FileItem.FromString)); BundleFiles.AddRange(stuff.GetArray(nameof(BundleFiles), FileItem.FromString)); StuffFiles.AddRange(stuff.GetArray(nameof(StuffFiles), FileItem.FromString)); ForeignSourceFiles.AddRange(stuff.GetArray(nameof(ForeignSourceFiles), ForeignItem.FromString)); ExtensionsBackends.AddRange(stuff.GetArray(nameof(ExtensionsBackends))); Namespaces.AddRange(stuff.GetArray(nameof(Namespaces))); }
public override void Execute(IEnumerable <string> args) { var flags = StuffFlags.Print; var defines = new List <string>(StuffFile.DefaultDefines); var files = new OptionSet { { "a|all", x => flags |= StuffFlags.AcceptAll }, { "D=", defines.Add }, { "U=", x => defines.Remove(x) } } .Parse(args) .GetFiles("*.stuff"); foreach (var file in files) { StuffObject.Load(file, flags, defines); } }
public void InstallFile(string filename) { switch ((Path.GetExtension(filename) ?? "").ToUpperInvariant()) { case ".NUPKG": case ".UPK": Install(new UpkFile(filename)); break; case ".PACKAGES": InstallAll(StuffObject.Load(filename)); break; case ".UNOPROJ": InstallAll(Project.Load(filename)); break; default: throw new InvalidOperationException("Unsupported file: " + filename.ToRelativePath()); } }
void LoadStuff(string filename, StuffFlags flags, IEnumerable <string> defines) { var solutionDir = Path.GetDirectoryName(filename); foreach (var solutionFolder in StuffObject.Load(filename, flags, defines)) { if (solutionFolder.Key.StartsWith("AssemblyInfo.")) { var key = solutionFolder.Key; var property = key.Substring(key.IndexOf('.') + 1); _assemblyInfo[property] = solutionFolder.Value?.ToString(); continue; } var folderGuid = GetFolderGuid(solutionFolder.Key); foreach (var projectPath in solutionFolder.Value.Lines() .Select(x => Path.Combine(solutionDir, x))) { if (Directory.Exists(projectPath)) { foreach (var projectFile in Directory.EnumerateFiles(projectPath, "*.csproj")) { AddProject(projectFile, folderGuid); } } else if (File.Exists(projectPath)) { AddProject(projectPath, folderGuid); } else { Log.Warning(projectPath.Relative() + ": No C# project(s) found"); } } } }
public static bool IsUpToDate(Log log, string filename, StuffFlags flags = 0, IEnumerable <string> optionalDefines = null) { try { var parentDir = Path.GetDirectoryName(filename); foreach (var item in StuffObject.Load(filename, flags, optionalDefines)) { var itemKey = item.Key.Replace('/', Path.DirectorySeparatorChar); var itemFile = Path.Combine(parentDir, ".uno", "stuff", itemKey); var targetDir = Path.Combine(parentDir, itemKey); if (!IsItemUpToDate(log, targetDir, itemFile, item.Value?.ToString(), flags)) { return(false); } } return(true); } finally { DownloadCache.AutoCollect(log); } }
public PackageCache(Log log, UnoConfig config, PackageManager pm) : base(log ?? Log.Null) { _pm = pm; if (config == null) { config = UnoConfig.Current; } foreach (var src in config.GetFullPathArray("Packages.SourcePaths")) { _sourcePaths.AddOnce(Path.Combine(src, "build")); } foreach (var src in config.GetFullPathArray("Packages.SearchPaths", "Packages.InstallDirectory")) { _searchPaths.AddOnce(src); } foreach (var file in config.GetFullPathArray("Packages.LockFiles")) { try { Log.VeryVerbose("Package file: " + file); foreach (var e in StuffObject.Load(file)) { _locks[e.Key] = "" + e.Value; } } catch (Exception e) { Log.Trace(e); Log.Warning("Failed to load " + file.Quote() + ": " + e.Message); } } }
public static PackageFile Load(string dir) { return new PackageFile(StuffObject.Load(GetName(dir)), dir); }
public override void Execute(IEnumerable <string> args) { string url = null; string apiToken = null; string outDir = null; var files = new OptionSet { { "u=|url=", x => url = x }, { "t=|a=|api-token=", x => apiToken = x }, { "o=|out-dir=|output-dir=", x => outDir = x }, } .Parse(args) .GetFiles("*.stuff-upload"); if (string.IsNullOrEmpty(url)) { throw new ArgumentException("--url was not specified"); } if (outDir != null) { Disk.CreateDirectory(outDir); } foreach (var f in files) { var result = new Dictionary <string, string>(); var sizes = new Dictionary <string, long>(); var stuffDir = outDir ?? Path.GetDirectoryName(f); foreach (var item in StuffObject.Load(f, StuffFlags.AcceptAll)) { if (item.Value == null) { continue; } using (var web = new WebClient()) { var uploadFile = Path.Combine(Path.GetDirectoryName(f), item.Value.ToString()); Log.WriteLine(ConsoleColor.Blue, "stuff: POST " + uploadFile.Relative()); try { if (apiToken != null) { web.Headers.Add("X-API-Token: " + apiToken); } var bytes = web.UploadFile(url, uploadFile); var logFile = Path.Combine(stuffDir, item.Value + ".log"); Log.Event(IOEvent.Write, logFile); File.WriteAllBytes(logFile, bytes); result.Add(item.Key, GetUrl(logFile, bytes)); sizes.Add(item.Key, new FileInfo(uploadFile).Length); } catch (Exception e) { throw new Exception(uploadFile.Relative() + ": " + e.Message, e); } } } var stuffFile = Path.Combine(stuffDir, Path.GetFileNameWithoutExtension(f) + ".stuff"); Log.Event(IOEvent.Write, stuffFile); // This is not the optimal solution, but it works for now. // In reality there could be multiple conditions in the file, and so on, // but we don't want to write a parser now. var condition = GetFirstCondition(f); using (var w = new StreamWriter(stuffFile) { NewLine = "\n" }) { foreach (var item in result) { var line = "/* " + ConvertBytesToMegabytes(sizes[item.Key]) .ToString("0.00", CultureInfo.InvariantCulture) + "MB */ " + item.Key.Literal() + ": " + item.Value.Literal(); Console.WriteLine(line + ( !string.IsNullOrEmpty(condition) ? " (" + condition + ")" : null)); w.WriteConditional(condition, line); } } } }