public bool Run(Assembly assm, string ResourceName, string OutputPath, TaskLoggingHelper Log) { // Ensure our output directory exists if (!Directory.Exists(Path.GetDirectoryName(OutputPath))) { Directory.CreateDirectory(Path.GetDirectoryName(OutputPath)); } // Copy out one of our embedded resources to a path using (var from = GetManifestResourceStream(ResourceName)) { // If the resource already exists, only overwrite if it's changed if (File.Exists(OutputPath)) { var hash1 = MonoAndroidHelper.HashFile(OutputPath); var hash2 = MonoAndroidHelper.HashStream(from); if (hash1 == hash2) { Log.LogDebugMessage("Resource {0} is unchanged. Skipping.", OutputPath); return(true); } } // Hash calculation read to the end, move back to beginning of file from.Position = 0; // Write out the resource using (var to = File.Create(OutputPath)) Copy(from, to); Log.LogDebugMessage("Wrote resource {0}.", OutputPath); } return(true); }
public static void InitializeAndroidLogger(TaskLoggingHelper log) { AndroidLogger.Error += (task, message) => log.LogError(task + " " + message); AndroidLogger.Warning += (task, message) => log.LogWarning(task + " " + message); AndroidLogger.Info += (task, message) => log.LogMessage(task + " " + message); AndroidLogger.Debug += (task, message) => log.LogDebugMessage(task + " " + message); }
void CreateImportFor(bool isNestedSrc, IEnumerable <TypeDefinition> types, CodeMemberMethod method) { foreach (var type in types) { // If the library was written in F#, those resource ID classes are not nested but rather combined with '_'. var srcClassRef = new CodeTypeReferenceExpression( new CodeTypeReference(primary_name + (isNestedSrc ? '.' : '_') + type.Name, CodeTypeReferenceOptions.GlobalReference)); // destination language may not support nested types, but they should take care of such types by themselves. var typeFullName = type.FullName.Replace('/', '.'); var dstClassRef = new CodeTypeReferenceExpression( new CodeTypeReference(typeFullName, CodeTypeReferenceOptions.GlobalReference)); foreach (var field in type.Fields) { var dstField = new CodeFieldReferenceExpression(dstClassRef, field.Name); var srcField = new CodeFieldReferenceExpression(srcClassRef, field.Name); var fieldName = CreateIdentifier(type.Name, field.Name); if (!resourceFields.Contains(fieldName)) { Log.LogDebugMessage($"Value not found for {typeFullName}.{field.Name}, skipping..."); continue; } // This simply assigns field regardless of whether it is int or int[]. method.Statements.Add(new CodeAssignStatement(dstField, srcField)); } } }
void CreateImportFor(string declaringTypeFullName, TypeDefinition type, CodeMemberMethod method, MetadataReader reader) { var typeName = reader.GetString(type.Name); var srcClassRef = new CodeTypeReferenceExpression( new CodeTypeReference($"{primary_name}.{typeName}", CodeTypeReferenceOptions.GlobalReference)); var dstClassRef = new CodeTypeReferenceExpression( new CodeTypeReference($"{declaringTypeFullName}.{typeName}", CodeTypeReferenceOptions.GlobalReference)); foreach (var handle in type.GetFields()) { var fieldName = reader.GetString(reader.GetFieldDefinition(handle).Name); var dstField = new CodeFieldReferenceExpression(dstClassRef, fieldName); var srcField = new CodeFieldReferenceExpression(srcClassRef, fieldName); var fieldIdentifier = CreateIdentifier(typeName, fieldName); if (!resourceFields.Contains(fieldIdentifier)) { Log.LogDebugMessage($"Value not found for {fieldIdentifier}, skipping..."); continue; } // This simply assigns field regardless of whether it is int or int[]. method.Statements.Add(new CodeAssignStatement(dstField, srcField)); } }
public static string GetBundledAssemblyName(string path, TaskLoggingHelper log) { string name = Path.GetFileName(path); // A bit of a hack to support satellite assemblies. They all share the same name but // are placed in subdirectories named after the locale they implement. Also, all of // them end in .resources.dll, therefore we can use that to detect the circumstances. if (name.EndsWith(".resources.dll", StringComparison.OrdinalIgnoreCase)) { string dir = Path.GetDirectoryName(path); int idx = dir.LastIndexOf(Path.DirectorySeparatorChar); if (idx >= 0) { name = dir.Substring(idx + 1) + Path.DirectorySeparatorChar + name; log.LogDebugMessage($"Storing satellite assembly '{path}' with name '{name}'"); } else { log.LogWarning($"Warning: satellite assembly {path} doesn't have locale path prefix, name conflicts possible"); } } return(name); }
public override void LogMessage(string message, params object [] values) { logger.LogDebugMessage(message, values); }
public override void LogMessage(string message) { logger.LogDebugMessage("{0}", message); }