Commits

Kit Roed committed c0c6da1

Update Reader class to read additional fields for FPW .scx files.

Made it easier to add fields to extract, and testing for presence of the Column
in the VFP file's DataTable.

Comments (0)

Files changed (2)

FoxProReader/Reader.cs

     /// </summary>
     public class Reader
     {
+        //private string[] _scxFields = { "objname", "properties", "protected", "methods", "reserved3" };
+
         public static string ProcessFoxProFile(string p)
         {
             string vfpFilePath = Path.GetFullPath(p);
             OleDbCommand command = new OleDbCommand(queryString, conn);
             command.Parameters.Add("@p1", OleDbType.VarChar).Value = vfpFileName;
             OleDbDataAdapter da = new OleDbDataAdapter(command);
-            
+
 
             try
             {
             {
                 numberOfErrors++;
             }
+            catch (InvalidOperationException)
+            {
+                numberOfErrors++;
+            }
             var contents = new StringBuilder();
 
-            if (vfpFileExtension == ".vcx" || vfpFileExtension == ".scx")
+            if (vfpFileExtension == ".vcx" || vfpFileExtension == ".scx" || vfpFileExtension == ".frx")
             {
-                foreach (DataRow r in dt.Rows)
-                {
-                    contents.Append(r["objname"].ToString());
-                    contents.Append(r["properties"].ToString()); // list of all the custom properties added
-                    contents.Append(r["protected"].ToString());
-                    contents.Append(r["methods"].ToString()); // majority of source code
-                    contents.Append(r["reserved3"].ToString()); // comments
-
-                }
+                string[] scxFields = {
+                                         "objname", "properties", "protected", "methods", "reserved3",
+                                         "name", "expr", "picture", "comment", "tag", "tag2", "rangelo", "when", "valid", "error", "message", "show", "activate", "deactivate", "proccode", "setupcode", "initalval"
+                                     };
+                contents.Append(ExtractVfpFields(dt, scxFields));
+            }
+            else if (vfpFileExtension == ".mnx")
+            {
+                string[] mnxFields = { "name", "prompt", "command", "message", "procedure", "keyname", "keylabel", "skipfor", "levelname", "comment" };
+                contents.Append(ExtractVfpFields(dt, mnxFields));
             }
             else if (vfpFileExtension == ".dbc")
             {
                     contents.Append(r["objecttype"].ToString().Trim());
                     contents.Append(" ");
                     contents.Append(r["objectname"].ToString().Trim());
-                    contents.Append(Environment.NewLine);
+                    contents.AppendLine();
                     if (r["objectname"].ToString().Contains("StoredProceduresSource"))
                     {
                         //contents.Append(Convert.ToString(r["code"]));
                     }
                 }
             }
-            else if (vfpFileExtension == ".frx")
+            else if (vfpFileExtension == ".pjx")
             {
                 foreach (DataRow r in dt.Rows)
                 {
-                    contents.AppendLine(r["name"].ToString());
-                    contents.AppendLine(r["expr"].ToString());
-                    contents.AppendLine(r["comment"].ToString());
+                    contents.Append(r["name"].ToString());
+                    contents.Append(" ");
+                    contents.Append(r["type"].ToString());
+                    if (r["type"].ToString().Contains("H"))
+                    {
+                        contents.Append(" ");
+                        contents.Append(r["devinfo"].ToString());
+                    }
+                    contents.AppendLine();
                 }
             }
-            else if (vfpFileExtension == ".mnx")
-            {
-                foreach (DataRow r in dt.Rows)
-                {
-                    contents.AppendLine(r["name"].ToString());
-                    contents.AppendLine(r["prompt"].ToString());
-                    contents.AppendLine(r["command"].ToString());
-                    contents.AppendLine(r["message"].ToString());
-                    contents.AppendLine(r["procedure"].ToString());
-                    contents.AppendLine(r["keyname"].ToString());
-                    contents.AppendLine(r["keylabel"].ToString());
-                    contents.AppendLine(r["skipfor"].ToString());
-                    contents.AppendLine(r["levelname"].ToString());
-                    contents.AppendLine(r["comment"].ToString());
-                }
-            }
-            else if (vfpFileExtension == ".pjx")
-            {
-                throw new NotImplementedException();
-            }
 
             return contents.ToString();
         }
+
+        static private string ExtractVfpFields(DataTable vfpFile, string[] fieldsToExtract)
+        {
+            var contents = new StringBuilder();
+            foreach (DataRow r in vfpFile.Rows)
+            {
+                foreach (string f in fieldsToExtract)
+                {
+                    try
+                    {
+                        if (r.Table.Columns.Contains(f) && r[f].ToString().Length > 0)
+                        {
+                            contents.AppendLine(r[f].ToString());
+                        }
+                    }
+                    catch (ArgumentException)
+                    {
+
+                    }
+                }
+            }
+            return contents.ToString();
+        }
     }
 }
 - `methods`
 - `reserved3`
 
+### FoxPro for Windows (.scx) has more fields:
+
+- `name`
+- `expr`
+- `picture`
+- `comment`
+- `tag`
+- `tag2`
+- `rangelo`
+- `when`
+- `valid`
+- `error`
+- `message`
+- `show`
+- `activate`
+- `deactivate`
+- `proccode`
+- `setupcode`
+- `initalval`
 
 ##Database Container (.dbc) fields that need to be grabbed for indexing
 
 - `levelname`
 - `comment`
 
+##Project (.pjx) fields that need to be grabbed for indexing
+
+- `name`
+- `type` (`'H'` appears to be for Project info, `'P'` for prg, `'V'`, for classlib, `'T'` is config.fpw, `'K'` is form etc.)
+- `devinfo` for when `type == 'H'` contains the developer name as a string.
+