12using System.Text.RegularExpressions;
13using System.Collections.Generic;
17public static class AutoCopywriteHeader {
19 private static Regex beginPattern =
new Regex(
@"^\/\*");
20 private static Regex endPattern =
new Regex(
@"\*\/" );
29 private static string[] apacheCopywriteNotice = {
"/******************************************************************************",
30 " * Copyright (C) Ultraleap, Inc. 2011-2020. *",
32 " * Use subject to the terms of the Apache License 2.0 available at *",
33 " * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *",
34 " * between Ultraleap and you, your company or other organization. *",
35 " ******************************************************************************/"};
37 private static string[] searchFolders = {
"LeapMotion" };
39 [MenuItem(
"Assets/Update Copywrite Headers")]
40 public static void PopulateAutoHeaders() {
41 List<string> files =
new List<string>();
42 foreach (var folder
in searchFolders) {
44 files.AddRange(
Directory.GetFiles(Path.Combine(
"Assets",
"Plugins", folder),
"*.cs", SearchOption.AllDirectories));
45 }
catch (Exception e) {
46 Debug.LogException(e);
50 StringBuilder builder =
new StringBuilder();
53 for (
int i = 0; i < files.Count; i++) {
54 string filename = files[i];
56 if (EditorUtility.DisplayCancelableProgressBar(
"Updating copywrite notices",
57 "Updating " + Path.GetDirectoryName(filename) +
"...",
58 i / (files.Count - 1.0f))) {
62 if (tryBuildFile(filename, builder)) {
63 File.WriteAllText(filename, builder.ToString());
65 Debug.LogWarning(
"Could not add header to " + filename);
71 EditorUtility.ClearProgressBar();
72 AssetDatabase.Refresh();
76 private static bool tryBuildFile(
string filename, StringBuilder builder) {
77 using (var reader =
File.OpenText(filename)) {
80 line = reader.ReadLine();
86 }
while (line.Trim().Length == 0);
89 if (beginPattern.IsMatch(line)) {
91 line = reader.ReadLine();
97 }
while (!endPattern.IsMatch(line));
98 line = reader.ReadLine();
101 if (line.Trim().Length == 0) {
102 line = reader.ReadLine();
113 foreach (var noticeLine
in apacheCopywriteNotice) {
114 builder.AppendLine(noticeLine);
127 builder.AppendLine();
130 builder.AppendLine(line);
134 line = reader.ReadLine();
140 builder.AppendLine(line);