ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/EmuXPortal/branches/mono/EmuXPortal.Cacher/Program.cs
Revision: 406
Committed: Tue Sep 24 03:35:47 2019 UTC (2 years, 10 months ago) by william
File size: 5818 byte(s)
Log Message:
add support to rebuild cache with commandline option: --rebuild

File Contents

# Content
1 #define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
2 //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
3 //#define DEV_DEBUG
4
5 #if DEV_DEBUG
6 #warning DEV_DEBUG is enabled
7 #endif
8 using System;
9 using System.IO;
10 using System.Collections.Generic;
11 using System.Linq;
12 using System.Text;
13 using EmuXPortal.Api;
14 using Enterprise.Logging;
15 using Enterprise.CrossPlatform;
16 using System.Windows.Forms;
17 using System.Threading;
18
19 namespace EmuXPortal.Cacher
20 {
21 static class Program
22 {
23 static bool bUserAbort = false;
24 static void Pause()
25 {
26 #if DEV_DEBUG
27 Console.WriteLine("Please press any key to continue...");
28 Console.ReadKey(true);
29 #endif
30 }
31 #region logging support
32 static void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }
33 static void OnLogFlush(string logmessage)
34 {
35 //if (this.IsDisposed) { return; }
36 ////UpdateStatus(logmessage);
37 ////UpdateLogOutput(logmessage);
38 //Application.DoEvents();
39 }
40 #endregion
41 static void ProgressReport(object sender, ReportProgressEventArgs e)
42 {
43 string str = string.Empty;
44 int progress = e.Progress;
45 if (e.UserState == null)
46 {
47 str = string.Empty;
48 }
49 else
50 {
51 str = e.UserState.ToString();
52 }
53 Console.WriteLine("{0} [{1}]", str, progress);
54 }
55 public static void Main (string[] args)
56 {
57 #region logging support
58 string log_path = Application.StartupPath;
59 string log_filename = string.Format ("{0}.log", typeof(Program).Assembly.GetName ().Name);
60 FileInfo log_file = new FileInfo (OSInfo.FormatPath (string.Format (@"{0}\{1}", log_path, log_filename)));
61
62 gLog.CreateLog (log_file.Name, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs> (Log_OnFlush));
63 #if DEBUG
64 LogLevel gLevel = gLog.LogLevel;
65 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
66 gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
67 #else
68 gLevel |= LogLevel.kLogLevel_VerboseDebug;
69 #endif
70 gLevel |= LogLevel.kLogLevel_Debug;
71 gLog.SetLogLevel (gLevel);
72 #else
73 LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
74 // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
75 #if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
76 gLevel &= ~LogLevel.kLogLevel_Debug;
77 #else
78 gLevel |= LogLevel.kLogLevel_Debug;
79 #endif
80 gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode
81 gLog.SetLogLevel(gLevel);
82 #endif
83 #endregion
84
85 Console.CancelKeyPress += Console_CancelKeyPress;
86
87 gLog.ReportProgressEvent = new EventHandler<ReportProgressEventArgs> (ProgressReport);
88 gLog.Info.WriteLine ("Log Created: {0}", new object[] { DateTime.Now.ToString () });
89 #if DEV_DEBUG
90 //List<string> cargs = new List<string>() { string.Format("--rootpath=\"{0}\"", @"/home/william/Media/GameRoms") };
91 //List<string> cargs = new List<string>() { string.Format("--platformpath=\"{0}\"", @"/home/william/temp/ROM_TEST/SG") };
92 List<string> cargs = new List<string>() { string.Format("--platformpath=\"{0}\"", @"/home/william/Media/GameRoms/SG") };
93 //List<string> cargs = new List<string>() { string.Format("--platformpath=\"{0}\"", @"/home/william/Media/GameRoms/PC") };
94 //List<string> cargs = new List<string>() { "--dump-cache" };
95 #else
96 List<string> cargs = new List<string> (args);
97 #endif
98 bool bHaveRomPath = false;
99 bool bRegenAllCache = false;
100 string platform_path = "";
101 string root_path = "";
102 foreach (var carg in cargs) {
103 if (carg.ToLower ().StartsWith ("--platformpath="))
104 {
105 platform_path = carg.Replace ("--platformpath=", "").Replace ("\"", "");
106 DirectoryInfo di = new DirectoryInfo (platform_path);
107 if (!di.Exists) {
108 Console.WriteLine ("ERROR: platform path does not exist: '{0}'", platform_path);
109 break;
110 }
111 bHaveRomPath = true;
112 break;
113 }
114 else if (carg.ToLower ().StartsWith ("--rootpath"))
115 {
116 root_path = carg.Replace ("--rootpath=", "").Replace ("\"", "");
117 bRegenAllCache = true;
118 break;
119 }
120 }
121 if (bHaveRomPath) {
122 GenerateCache (platform_path);
123 Pause ();
124 } else if (bRegenAllCache) {
125 BuildAll ();
126 Pause ();
127 }
128 else
129 {
130 ShowUsage();
131 }
132 }
133 static void ShowUsage()
134 {
135 Console.WriteLine("usage: EmuXPortal.Cacher.exe --platformpath=\"path\"");
136 Console.WriteLine(" path --> the platform path to generate the cache for");
137 Console.WriteLine("usage: EmuXPortal.Cacher.exe --rootpath=\"path\"");
138 Console.WriteLine(" no arguments -- the root path to generate cache for (it contents all of the platforms to cache)");
139 }
140
141 static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
142 {
143 bUserAbort = true;
144 e.Cancel = true;
145 }
146 static bool OnAbort()
147 {
148 return bUserAbort;
149 }
150 static void GenerateCache (string platform_path)
151 {
152 gLog.Warn.WriteLine ("Building cache for: {0}", platform_path);
153 IPlatformCache cache = PlatformCache.Create(new AbortEvent(OnAbort), platform_path, false);
154 cache = null;
155 }
156 static void BuildAll ()
157 {
158 gLog.Warn.WriteLine ("Rebuilding All Caches");
159 IPlatformCache cache = PlatformCache.Create(new AbortEvent(OnAbort), true);
160 }
161 }
162 }