Ejemplo n.º 1
0
        public static void initialize(Main pMain)
        {
            m_pMain = pMain;
            m_pWebClient = new CGWebClient();
            m_pWebClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(m_pWebClient_DownloadFileCompleted);
            m_pWebClient.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(m_pWebClient_DownloadProgressChanged);

            if (!System.IO.File.Exists(@"pak\Files\tile.p000"))
                m_pWebClient.DownloadFile(WEBSITE + "launcher/new_patch.xml", "patch.xml");
            else if (!System.IO.File.Exists(@"pak\World\_test$sample_1.p000"))
                m_pWebClient.DownloadFile(WEBSITE + "launcher/new_patch.xml", "patch.xml");
            else
                m_pWebClient.DownloadFile(WEBSITE + "launcher/patch.xml", "patch.xml");

            try
            {
                using (System.Xml.XmlTextReader pXmlTextReader = new System.Xml.XmlTextReader(Directory.GetCurrentDirectory() + "/patch.xml"))
                //using (System.Xml.XmlTextReader pXmlTextReader = new System.Xml.XmlTextReader( WEBSITE + "files/patch.xml"))
                {
                    int x = 0;

                    while (pXmlTextReader.ReadToFollowing("PATCHNODE"))
                    {
                        x++;
                        m_pMain.Status = "Interpreting Patch Information " + x + "...";
                        if (pXmlTextReader.MoveToFirstAttribute())
                        {
                            string strFilename = pXmlTextReader.GetAttribute("file").Replace("./", "");
                            string strCurrDir = System.IO.Directory.GetCurrentDirectory();
                            try
                            {
                                string Dir = Path.GetDirectoryName(strFilename);
                                if (!Directory.Exists(Dir) && Dir != "")
                                    Directory.CreateDirectory(Dir);
                            }
                            catch
                            {
                                m_pMain.Status = "Failed to create or read folder info.";
                            }
                            //foreach (string strTemp in strFilename.Split('/'))
                            //{
                            //    if (!strTemp.Contains("."))
                            //    {
                            //        System.IO.Directory.CreateDirectory(strTemp);
                            //        continue;
                            //    }
                            //}

                            uint nChecksum = 0;

                            if (pXmlTextReader.ReadToFollowing("CHECKSUM"))
                            {
                                nChecksum = (uint)pXmlTextReader.ReadElementContentAs(typeof(uint), null);
                            }
                            try
                            {
                                FileInfo FI = new FileInfo(strFilename);
                                if (strFilename.ToLower() == Path.GetFileName(Application.ExecutablePath).ToLower())
                                {
                                    FileInfo FI2 = new FileInfo(strFilename + "_");
                                    if (FI2.Exists)
                                        FI2.Delete();
                                    Thread.Sleep(500);
                                    FI.CopyTo(strFilename + "_");
                                    uint crc = getFileCrc(strFilename + "_");
                                    FI2 = new FileInfo(strFilename + "_");
                                    if (FI2.Exists)
                                        FI2.Delete();
                                    if (crc != nChecksum)
                                    {
                                        PatchSelf = true;
                                        m_pUpdateList.Add(strFilename);
                                    }
                                    continue;
                                }
                                if (!FI.Exists)
                                    m_pUpdateList.Add(strFilename);
                                else
                                {
                                    uint crc = getFileCrc(strFilename);
                                    if (crc != nChecksum)
                                    {
                                        m_pUpdateList.Add(strFilename);
                                    }
                                }
                            }
                            catch (Exception E)
                            {
                                if (E.Message.Contains("msvcr71.dll' because it is being used by another process"))
                                {
                                    //ignore because it's used by .net and gunz needs it...  note that this is a possible abuse for exploitation
                                }
                                else
                                {
                                    MessageBox.Show("Some of the files (" + strFilename + ") that need to be patched/edited are currently in use.  Make sure SoulHunterZ is closed.  If this error persists, restart your computer.", "Fatal Error");
                                    Application.Exit();
                                }
                            }

                            System.IO.Directory.SetCurrentDirectory(strCurrDir);
                        }
                    }
                }
            }
            catch
            {
                m_pMain.Status = "Failed to get or read patch info.";
                m_pWebClient.Dispose();
                return;
            }

            m_pMain.BarTotalMax = m_pUpdateList.Count;
            m_pMain.BarTotalVal = m_pMain.BarTotalMax;
            m_pMain.BarCurVal = m_pMain.BarCurMax;
            updateNext();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                Class.AppLogs      log            = new Class.AppLogs();
                Class.Orchestrator core           = new Class.Orchestrator();
                string             envioCorrectos = ConfigurationManager.AppSettings["destinationFolder"];
                int    factura           = 0;
                int    indexFileNameList = 0;
                String fecha             = String.Empty;
                string UUID           = String.Empty;
                string SATCertificate = String.Empty;
                string rfc            = String.Empty;
                log.CreateLog();
                core.delProcessedFiles(); // Borrado de archivos ya procesados
                Console.WriteLine("Inicia el proceso de sincronización en Epicor...");

                //Obtención de archivos XML
                core.obtainXMLFiles();
                if (core.collector.Equals(""))
                {
                    log.writeContentToFile("No se encontraron archivos que leer, termina la ejecución");
                }
                else
                {
                    log.writeContentToFile(core.collector);
                }

                // Iniciando conexión a Epicor
                Epicor10.EpiAdapters epicor = new EpiAdapters("vordmaker", "maker2016");

                //Obtención de datos fiscales por cada XML
                foreach (String item in core.filesPath)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("Obteniendo datos del archivo " + item);
                    log.writeContentToFile("\n");
                    log.writeContentToFile("Obteniendo datos del archivo " + item);

                    System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(item);

                    while (reader.Read())
                    {
                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            if (reader.Name.Equals("cfdi:Emisor"))
                            {
                                if (reader.HasAttributes)
                                {
                                    Console.WriteLine("_cfdi:Emisor_");
                                    Console.WriteLine("Compañía: " + reader.GetAttribute("Nombre"));
                                    Console.WriteLine("RFC: " + reader.GetAttribute("Rfc"));
                                    rfc = reader.GetAttribute("Rfc");
                                    log.writeContentToFile("Compañía: " + reader.GetAttribute("Nombre"));
                                    log.writeContentToFile("RFC: " + reader.GetAttribute("Rfc"));
                                }
                            }

                            if (reader.Name.Equals("cfdi:Addenda"))
                            {
                                reader.ReadToFollowing("fa:AddendaComercial");
                                if (!reader.HasAttributes)
                                {
                                    reader.ReadToFollowing("fa:Empresa");
                                    factura = Convert.ToInt32(reader.GetAttribute("NumeroInterno"));
                                    Console.WriteLine("_cfdi:Empresa_");
                                    Console.WriteLine("Número Legal: " + reader.GetAttribute("NumeroLegal"));
                                    Console.WriteLine("Número Interno: " + reader.GetAttribute("NumeroInterno"));
                                    Console.WriteLine("Fecha Contable: " + reader.GetAttribute("FechaContable"));
                                    Console.WriteLine("Fecha Emision: " + reader.GetAttribute("FechaEmision"));

                                    log.writeContentToFile("Número Legal: " + reader.GetAttribute("NumeroLegal"));
                                    log.writeContentToFile("Número Interno: " + reader.GetAttribute("NumeroInterno"));
                                    log.writeContentToFile("Fecha Contable: " + reader.GetAttribute("FechaContable"));
                                    log.writeContentToFile("Fecha Emision: " + reader.GetAttribute("FechaEmision"));
                                }
                            }

                            if (reader.Name.Equals("cfdi:Complemento"))
                            {
                                reader.ReadToFollowing("tfd:TimbreFiscalDigital");
                                Console.WriteLine("_cfdi:Complemento_");
                                Console.WriteLine("UUID: " + reader.GetAttribute("UUID"));
                                UUID  = reader.GetAttribute("UUID");
                                fecha = reader.GetAttribute("FechaTimbrado");
                                Console.WriteLine("Fecha: " + reader.GetAttribute("FechaTimbrado"));
                                Console.WriteLine("SAT: " + reader.GetAttribute("noCertificadoSAT")); // Versión 3.2
                                SATCertificate = reader.GetAttribute("noCertificadoSAT");
                                log.writeContentToFile("UUID: " + reader.GetAttribute("UUID"));
                                log.writeContentToFile("Fecha: " + reader.GetAttribute("FechaTimbrado"));
                                log.writeContentToFile("SAT: " + reader.GetAttribute("noCertificadoSAT"));
                            }

                            /*
                             * if (reader.Name.Equals("cfdi:Comprobante"))
                             * {
                             *  if (reader.HasAttributes)
                             *  {
                             *      Console.WriteLine("_cfdi:Comprobante_");
                             *      Console.WriteLine("Version: " + reader.GetAttribute("version"));
                             *      Console.WriteLine("TipoComprobante: " + reader.GetAttribute("tipoDeComprobante"));
                             *  }
                             * }
                             */

                            /*
                             * if (reader.Name.Equals("cfdi:Receptor"))
                             * {
                             *  if (reader.HasAttributes)
                             *  {
                             *      Console.WriteLine("_cfdi:Receptor_");
                             *      Console.WriteLine("RFC: " + reader.GetAttribute("rfc"));
                             *  }
                             * }
                             */
                        }
                    }

                    //Actualizacion Epicor
                    Console.WriteLine("Actualizando UUID de la factura...");
                    string empresa = core.companyToConnect(rfc);
                    Console.WriteLine("Conectando a ... " + empresa);

                    epicor.setCompany(empresa);
                    if (epicor.EventCollector.Equals(""))
                    {
                        epicor.UpdateInvcHeader(factura, UUID, SATCertificate, fecha);
                        if (epicor.EventCollector.Equals(""))
                        {
                            Console.WriteLine("Actualización de datos completa.");
                            log.writeContentToFile("Actualización de datos completa.");

                            reader.Close();
                            string destination = System.IO.Path.Combine(envioCorrectos, core.fileNames[indexFileNameList]);
                            System.IO.File.Copy(item, destination);
                            System.IO.File.Delete(item);
                        }
                        else
                        {
                            Console.WriteLine("Ocurrió un error al actualizar la información \n" + epicor.EventCollector);
                            log.writeContentToFile("Ocurrió un error al actualizar la información \n" + epicor.EventCollector);
                        }
                    }
                    else
                    {
                        Console.WriteLine(epicor.EventCollector);
                        log.writeContentToFile(epicor.EventCollector);
                    }

                    Console.WriteLine("\n");
                    log.writeContentToFile("\n");
                    indexFileNameList++;
                }
                log.writeContentToFile("Hemos terminado !!!");
            }
            catch (Exception rmp)
            {
                Console.WriteLine(rmp.StackTrace);
            }
            Console.WriteLine("Hemos terminado !!!");
        }
 //Method two: Get is medium trust (get if config is set as medium trust)
 private static bool IsMediumTrustSetInConfig()
 {
     bool result = false;
     try
     {
         string webConfigFile = System.IO.Path.Combine(System.Web.HttpContext.Current.Request.PhysicalApplicationPath, "web.config");
         System.Xml.XmlTextReader webConfigReader = new System.Xml.XmlTextReader(new System.IO.StreamReader(webConfigFile));
         webConfigReader.ReadToFollowing("trust");
         result = webConfigReader.GetAttribute("level") == "Medium";
         webConfigReader.Close(); //Close before return
         return result;
     }
     catch
     {
         return result;
     }
 }
Ejemplo n.º 4
0
        protected ReadContext ReadNodeProcess(string filePath, string nodeName)
        {
            FileStream stream = new FileStream(filePath, FileMode.Open);

            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(stream);
            ReadArgs    readArgs            = null;
            ReadContext context             = new ReadContext();
            bool        readIsFinish        = false;

            if (nodeName == null)
            {
                reader.Read();
            }
            else
            {
                reader.ReadToFollowing(nodeName);
            }
            do
            {
                int nowDepth = reader.Depth;
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element:
                    ConsoleLog.WriteLine(System.Xml.XmlNodeType.Element + "-" + reader.Name);
                    //该条件成立时,判定读取节点为GroupNode
                    if (context.PreviousNodeType == System.Xml.XmlNodeType.Element)
                    {
                        readArgs.Type = XmlNodeType.Group;
                        ReadSingleNodeStart?.Invoke(context, readArgs);
                        if (reader.Depth == context.PreviousDepth && readArgs.Name == nodeName)
                        {
                            readIsFinish = true;
                            context.PopParentNode();
                            break;
                        }
                    }

                    readArgs                 = new ReadArgs();
                    context.NodeIsEnd        = ReadElement(reader, readArgs, context);
                    context.PreviousNodeType = System.Xml.XmlNodeType.Element;
                    context.PreviousDepth    = nowDepth;
                    break;

                case System.Xml.XmlNodeType.Text:
                    ConsoleLog.WriteLine(System.Xml.XmlNodeType.Text + "-" + reader.Name);
                    //判定当前节点为ContentNode
                    readArgs.Type = XmlNodeType.Content;
                    ReadSingleNodeStart?.Invoke(context, readArgs);
                    context.NodeIsEnd        = ReadText(reader, readArgs, context);
                    context.PreviousNodeType = System.Xml.XmlNodeType.Text;
                    context.PreviousDepth    = nowDepth;
                    break;

                case System.Xml.XmlNodeType.EndElement:
                    ConsoleLog.WriteLine(System.Xml.XmlNodeType.EndElement + "-" + reader.Name);
                    //当条件成立时,判定节点为GroupNode
                    if (context.PreviousNodeType == System.Xml.XmlNodeType.Element)
                    {
                        readArgs.Type = XmlNodeType.Group;
                        ReadSingleNodeStart?.Invoke(context, readArgs);
                    }

                    context.NodeIsEnd = ReadEndElement(reader, readArgs, context);
                    ReadSingleNodeEnd?.Invoke(context, readArgs);
                    if (reader.Name == nodeName)
                    {
                        readIsFinish = true;
                    }
                    readArgs = new ReadArgs();
                    context.PreviousNodeType = System.Xml.XmlNodeType.EndElement;
                    context.PreviousDepth    = nowDepth;
                    break;
                }
                if (readIsFinish)
                {
                    break;
                }
            }while (reader.Read());
            reader.Close();
            return(context);
        }