Ejemplo n.º 1
0
        void PrecompileDirectoryTree(string strDirectory)
        {
            int      nRoot = Server.MapPath("/").Length;
            FileInfo objInfo;

            string[] arrFiles = Directory.GetFiles(strDirectory);
            for (int i = 0; i < arrFiles.Length; i++)
            {
                objInfo = new FileInfo(arrFiles[i]);
                if (objInfo.Name.EndsWith(".lang.php") && Response.IsClientConnected)
                {
                    if (objInfo.FullName.EndsWith(".lang.php"))
                    {
                        LanguagePackImport.InsertTerms(objInfo.FullName, false);
                        Response.Write(objInfo.FullName + ControlChars.CrLf);
                    }
                }
            }

            string[] arrDirectories = Directory.GetDirectories(strDirectory);
            for (int i = 0; i < arrDirectories.Length; i++)
            {
                objInfo = new FileInfo(arrDirectories[i]);
                if (objInfo.Name != "_vti_cnf")
                {
                    PrecompileDirectoryTree(objInfo.FullName);
                }
            }
        }
        protected void ImportFromStream(Stream stm)
        {
            // http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx
            // http://community.sharpdevelop.net/forums/738/ShowPost.aspx
            // The #ZipLib is licensed under a modified GPL. This modification grants you the right to use the compiled  .DLL in closed source applications.
            // Modifcations to the library however fall under the provisions of the GPL.
            Hashtable hashLanguages = new Hashtable();

            using (ZipInputStream stmZip = new ZipInputStream(stm))
            {
                ZipEntry theEntry = null;
                while ((theEntry = stmZip.GetNextEntry()) != null)
                {
                    string sFileName = Path.GetFileName(theEntry.Name);
                    if (sFileName != String.Empty)
                    {
                        Response.Write(theEntry.Name + "<br>" + ControlChars.CrLf);
                        if (theEntry.Name.EndsWith(".lang.php"))
                        {
                            string sLang = LanguagePackImport.GetLanguage(theEntry.Name);
                            // 11/13/2006 Paul.  SugarCRM still has not fixed their German language pack. Convert ge-GE to de-DE.
                            if (String.Compare(sLang, "ge-GE", true) == 0)
                            {
                                sLang = "de-DE";
                            }
                            // 08/22/2007 Paul.  Only insert the language record once.
                            if (!hashLanguages.ContainsKey(sLang))
                            {
                                CultureInfo culture = new CultureInfo(sLang);
                                if (culture == null)
                                {
                                    throw(new Exception("Unknown language: " + sLang));
                                }
                                SqlProcs.spLANGUAGES_InsertOnly(sLang, culture.LCID, true, culture.NativeName, culture.DisplayName);
                                if (chkTruncate.Checked)
                                {
                                    SqlProcs.spTERMINOLOGY_DeleteAll(sLang);
                                    hashLanguages.Add(sLang, String.Empty);
                                }
                            }
                            LanguagePackImport.InsertTerms(theEntry.Name, stmZip, chkForceUTF8.Checked);
                        }
                    }
                }
                // 01/12/2006 Paul.  Update internal cache.
                SplendidInit.InitTerminology();
                // 01/13/2006 Paul.  Clear the language cache.
                SplendidCache.ClearLanguages();
            }
        }
        void PrecompileDirectoryTree(string strDirectory)
        {
            if (!Directory.Exists(strDirectory))
            {
                return;
            }
            FileInfo objInfo;

            string[] arrFiles = Directory.GetFiles(strDirectory);
            for (int i = 0; i < arrFiles.Length; i++)
            {
                objInfo = new FileInfo(arrFiles[i]);
                if (Response.IsClientConnected)
                {
                    if (objInfo.FullName.EndsWith(".lang.php"))
                    {
                        LanguagePackImport.InsertTerms(objInfo.FullName, false);
                        Response.Write(objInfo.FullName + ControlChars.CrLf);
                    }
                    else if (objInfo.FullName.EndsWith(".html") && objInfo.FullName.IndexOf(".help.") >= 0)
                    {
                        LanguagePackImport.InsertHelp(objInfo.FullName, false);
                        Response.Write(objInfo.FullName + ControlChars.CrLf);
                    }
                }
            }

            string[] arrDirectories = Directory.GetDirectories(strDirectory);
            for (int i = 0; i < arrDirectories.Length; i++)
            {
                objInfo = new FileInfo(arrDirectories[i]);
                if (objInfo.Name != "_vti_cnf")
                {
                    PrecompileDirectoryTree(objInfo.FullName);
                }
            }
        }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Next")
     {
         reqFILENAME.Enabled = true;
         reqFILENAME.Validate();
         if (Page.IsValid)
         {
             Response.Write("<div id=\"divImportList\">" + ControlChars.CrLf);
             try
             {
                 HttpPostedFile pstIMPORT = fileIMPORT.PostedFile;
                 if (pstIMPORT != null)
                 {
                     if (pstIMPORT.FileName.Length > 0)
                     {
                         string sFILENAME       = Path.GetFileName(pstIMPORT.FileName);
                         string sFILE_EXT       = Path.GetExtension(sFILENAME);
                         string sFILE_MIME_TYPE = pstIMPORT.ContentType;
                         //string sLocalFile = Path.Combine(Path.GetTempPath(), sFILENAME);
                         //pstIMPORT.SaveAs(sLocalFile);
                         //ProcessDirectory(sLocalFile + "\\SugarRus\\manifest.php");
                         if (sFILE_MIME_TYPE == "application/x-zip-compressed")
                         {
                             // http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/default.aspx
                             // http://community.sharpdevelop.net/forums/738/ShowPost.aspx
                             // The #ZipLib is licensed under a modified GPL. This modification grants you the right to use the compiled  .DLL in closed source applications.
                             // Modifcations to the library however fall under the provisions of the GPL.
                             Hashtable hashLanguages = new Hashtable();
                             using (ZipInputStream stmZip = new ZipInputStream(pstIMPORT.InputStream))
                             {
                                 ZipEntry theEntry = null;
                                 while ((theEntry = stmZip.GetNextEntry()) != null)
                                 {
                                     string sFileName = Path.GetFileName(theEntry.Name);
                                     if (sFileName != String.Empty)
                                     {
                                         Response.Write(theEntry.Name + "<br>" + ControlChars.CrLf);
                                         if (theEntry.Name.EndsWith(".lang.php"))
                                         {
                                             string      sLang   = LanguagePackImport.GetLanguage(theEntry.Name);
                                             CultureInfo culture = new CultureInfo(sLang);
                                             if (culture == null)
                                             {
                                                 throw(new Exception("Unknown language: " + sLang));
                                             }
                                             SqlProcs.spLANGUAGES_InsertOnly(sLang, culture.LCID, true, culture.NativeName, culture.DisplayName);
                                             if (chkTruncate.Checked)
                                             {
                                                 if (!hashLanguages.ContainsKey(sLang))
                                                 {
                                                     SqlProcs.spTERMINOLOGY_DeleteAll(sLang);
                                                     hashLanguages.Add(sLang, String.Empty);
                                                 }
                                             }
                                             LanguagePackImport.InsertTerms(theEntry.Name, stmZip, chkForceUTF8.Checked);
                                         }
                                     }
                                 }
                                 // 01/12/2006 Paul.  Update internal cache.
                                 SplendidInit.InitTerminology();
                                 // 01/13/2006 Paul.  Clear the language cache.
                                 SplendidCache.ClearLanguages();
                             }
                         }
                         else
                         {
                             throw(new Exception("ZIP is the only supported format at this time."));
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                 lblError.Text = ex.Message;
             }
             finally
             {
                 Response.Write("</div>" + ControlChars.CrLf);
                 Page.RegisterClientScriptBlock("HideImportList", "<script type=\"text/javascript\">document.getElementById('divImportList').style.display='none';</script>");
             }
         }
     }
     else if (e.CommandName == "Back")
     {
     }
 }