Example #1
0
 IStyleInstance IStyleEngine.CreateInstance(string StyleName)
 {
     // this would look up StyleName in the loadedStyles list
     // if found, it will create a new instance of the Redirect
     Redirect item = loadedStyles.Find(i => i.GetInfo().name.ToLower() == StyleName.ToLower());
     if (item != null)
     {
         return item.CreateInstance();
     }
     else
     {
         return null;
     }
 }
Example #2
0
        private bool _loadRedirect(string sourcePath)
        {
            bool result = false;
            //MessageBox.Show(">>" + sourcePath);
            // enumerate the passed folder grabbing just the filename in lowercase
            List<string> newContents = new List<string>();
            foreach (string str in Directory.EnumerateFiles(sourcePath, "*.*"))
            {
                //MessageBox.Show(str);
                newContents.Add(Path.GetFileName(str).ToLower());
            }

            string baseName = Path.GetFileName(sourcePath);
            string dllName = baseName + ".dll";
            //MessageBox.Show("dllname>" + dllName);
            if (newContents.Contains("icon.png") && newContents.Contains(dllName))
            {
                // has dll and icon - that'll do for now
                try
                {
                    Assembly assembly = Assembly.LoadFrom(Path.Combine(sourcePath, dllName));
                    try
                    {
                        Redirect redirect = (Redirect)assembly.CreateInstance(baseName + "." + baseName, true);
                        redirect.BaseName = baseName;
                        if (redirect.Load())
                        {
                            loadedStyles.Add(redirect);
                            result = true;
                        }
                        else
                        {
                            //MessageBox.Show("redirect.Load()");
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("create instance " + baseName + "." + baseName + ">" + e.Message);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("loadfrom>" + e.Message);
                }
            }
            return result;
        }
Example #3
0
 int IStyleEngine.GetConfigWindow(string str)
 {
     if (str.Contains(":"))
     {
         string[] args = str.Split(':');
         // [0] should by the style name; [1] should be the query
         Redirect style = loadedStyles.Find(i => i.StyleName == args[0]);
         if (style != null)
         {
             WebAdminReply reply = style.DoWebAdmin(_GetQueryParameters(args[1]));
             this.lastRedirect = reply.RedirectURL;
             this.lastResponse = reply.ReplyHTML;
             return reply.StatusCode;
         }
     }
     return 0;
 }
Example #4
0
        void IStyleEngine.StyleAt(int Index, ref style_info Style)
        {
            if (Index == -1)
            {
                // don't ask...
                Style.Name = this.lastRedirect;
            }
            else if (Index == 0)
            {
                // return info about the engine
                Style.Name = "NetRedirect";
                Style.IconPath = Path.Combine(this.bootPath, "icon.png");
                Style.Date = LIB_DATE;
                Style.Major = LIB_VERSION;
                Style.Minor = LIB_REVISION;
            }
            else
            {
                Redirect item = loadedStyles[Index - 1];
                if (item != null)
                {
                    RedirectInfo info = item.GetInfo();
                    Style.Copyright = info.vendorCopyright;
                    Style.Date = info.date;
                    Style.Description = info.description;
                    Style.Flags = S_STYLE_FLAGS.S_STYLE_IS_WINDOWLESS | S_STYLE_FLAGS.S_STYLE_V42_CONTENT;

                    if (info.isConfigurable)
                        Style.Flags = Style.Flags | S_STYLE_FLAGS.S_STYLE_IS_CONFIGURABLE;

                    if (info.supportsWebAdmin)
                        Style.Flags = Style.Flags + 0x2000;             // S_STYLE_SUPPORTS_WEB_ADMIN

                    if (info.isWebRedirect)
                        Style.Flags = Style.Flags + 0x8000;             // S_STYLE_WEB_REDIRECT (R4.0)

                    Style.Major = info.versionMajor;
                    Style.Minor = info.versionMinor;
                    Style.Name = info.name;
                    Style.Path = Path.Combine(this.redirectsPath, item.BaseName);
//                    Style.Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), 
//                                              "full phat\\snarl\\redirects.net", item.baseName);

                    string schemeList = "";
                    foreach (KeyValuePair<string, string> scheme in info.schemes)
                    {
                        schemeList += scheme.Key + "=" + scheme.Value + "|";
                    }

                    Style.Schemes = schemeList.TrimEnd('|');
                    Style.SupportEmail = info.vendorEmail;
                    Style.URL = info.vendorURL;
                    // do after setting .Path!
                    Style.IconPath = Path.Combine(Style.Path, "icon.png");

                }
                else
                {
                    // invalid index
                    Style.Name = "???notfound???";
                }
            }
        }