예제 #1
0
 private bool importSearchProviders(string iniPath)
 {
     try
     {
         bool result = false;
         int  size   = 1024;
         var  buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("search_engines", null, null, buffer, size, iniPath) ==
                size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         var names     = buffer.Split('\0');
         var keys      = names.Where(n => n.Trim().Length > 0);
         var sqlList   = new List <string>();
         var providers = new List <PNSearchProvider>();
         foreach (var key in keys)
         {
             var query = new StringBuilder(1024);
             while (
                 PNInterop.GetPrivateProfileStringByBuilder("search_engines", key, "", query, query.Capacity,
                                                            iniPath) == query.Capacity - 1)
             {
                 query.Capacity *= 2;
             }
             providers.Add(new PNSearchProvider {
                 Name = key, QueryString = query.ToString()
             });
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO SEARCH_PROVIDERS (SP_NAME, SP_QUERY) VALUES(");
             sb.Append("'");
             sb.Append(key);
             sb.Append("', ");
             sb.Append("'");
             sb.Append(query);
             sb.Append("'");
             sb.Append(")");
             sqlList.Add(sb.ToString());
         }
         if (sqlList.Count > 0 && PNData.ExecuteTransactionForList(sqlList, PNData.ConnectionString))
         {
             result = true;
             foreach (var prv in providers)
             {
                 PNStatic.SearchProviders.RemoveAll(pr => pr.Name == prv.Name);
                 PNStatic.SearchProviders.Add(prv);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
예제 #2
0
 private bool importTags(string iniPath)
 {
     try
     {
         var result = false;
         var tags   = new StringBuilder(1024);
         while (
             PNInterop.GetPrivateProfileStringByBuilder("tags_pre", "tags", "", tags, tags.Capacity, iniPath) ==
             tags.Capacity - 1)
         {
             tags.Capacity *= 2;
         }
         if (tags.Length > 0)
         {
             var arr     = tags.ToString().Split(',');
             var listSql = new List <string>();
             foreach (var tag in arr)
             {
                 var sb = new StringBuilder();
                 sb.Append("INSERT OR REPLACE INTO TAGS (TAG) VALUES('");
                 sb.Append(tag);
                 sb.Append("')");
                 listSql.Add(sb.ToString());
             }
             if (PNData.ExecuteTransactionForList(listSql, PNData.ConnectionString))
             {
                 result = true;
                 foreach (string tag in arr)
                 {
                     if (!PNStatic.Tags.Contains(tag))
                     {
                         PNStatic.Tags.Add(tag);
                     }
                 }
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }
예제 #3
0
 private bool importExternals(string iniPath)
 {
     try
     {
         var result = false;
         var size   = 1024;
         var buffer = new string(' ', size);
         while (PNInterop.GetPrivateProfileString("external_programs", null, null, buffer, size, iniPath) ==
                size - 2)
         {
             // loop until sufficient buffer size
             size  *= 2;
             buffer = new string(' ', size);
         }
         var names     = buffer.Split('\0');
         var keys      = names.Where(n => n.Trim().Length > 0);
         var listSql   = new List <string>();
         var externals = new List <PNExternal>();
         foreach (string key in keys)
         {
             var prog = new StringBuilder(1024);
             while (
                 PNInterop.GetPrivateProfileStringByBuilder("external_programs", key, "", prog, prog.Capacity,
                                                            iniPath) == prog.Capacity - 1)
             {
                 prog.Capacity *= 2;
             }
             var data = prog.ToString().Split((char)1);
             var ext  = new PNExternal {
                 Name = key, Program = data[0]
             };
             var sb = new StringBuilder();
             sb.Append("INSERT OR REPLACE INTO EXTERNALS (EXT_NAME, PROGRAM, COMMAND_LINE) VALUES(");
             sb.Append("'");
             sb.Append(key);
             sb.Append("', ");
             sb.Append("'");
             sb.Append(data[0]);
             sb.Append("', ");
             sb.Append("'");
             if (data.Length == 2)
             {
                 sb.Append(data[1]);
                 ext.CommandLine = data[1];
             }
             sb.Append("'");
             sb.Append(")");
             listSql.Add(sb.ToString());
             externals.Add(ext);
         }
         if (listSql.Count > 0 && PNData.ExecuteTransactionForList(listSql, PNData.ConnectionString))
         {
             result = true;
             foreach (PNExternal ext in externals)
             {
                 PNStatic.Externals.RemoveAll(ex => ex.Name == ext.Name);
                 PNStatic.Externals.Add(ext);
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return(false);
     }
 }