コード例 #1
0
ファイル: CommunUpdater.cs プロジェクト: VLiance/Cwc-src
        /*
         *   public void fExtractSevenZip(string zipFileName, string targetDir)
         * {
         *   TraceManager.Add("Extract7z");
         *   string zPath = PathHelper.ToolDir + "/7z/7zG.exe";
         *   try
         *   {
         *       ProcessStartInfo pro = new ProcessStartInfo();
         *       pro.WindowStyle = ProcessWindowStyle.Hidden;
         *       pro.FileName = zPath;
         *       pro.Arguments = "x \"" + zipFileName + "\" -o" + targetDir;
         *       Process x = Process.Start(pro);
         *       x.WaitForExit();
         *   }
         *   catch (System.Exception Ex)
         *   {
         *
         *       TraceManager.Add("7z error : " + Ex.Message + " : " + Ex.Data + " : " + PathHelper.ToolDir + "/7z/7zG.exe");
         *       //DO logic here
         *   }
         * }*/

        public void fDownloadModule(string _sModule)
        {
            string _sFile = "";

            this.BeginInvoke((MethodInvoker) delegate
            {
                aChk[_sModule].Enabled = false;
                aStatus[_sModule].Text = "Downloading";
            });

            try
            {
                _sFile = _sModule + "_" + aLastVersion[_sModule].Text + "." + aLastCompression[_sModule];
                WebClient _client = new WebClient();
                _client.Proxy = null; //Important remove slow proxy down
                _client.DownloadProgressChanged += client_DownloadProgressChanged(_sModule);
                _client.DownloadFileCompleted   += DownloadFileCompleted(_sModule);
                TraceManager.Add("DownloadFile : " + BaseURL + _sFile);
                _client.DownloadFileAsync(new Uri(BaseURL + _sFile), sDownloadDir + "/" + _sModule + "_" + aLastVersionType[_sModule] + "." + aLastCompression[_sModule]);
            }
            catch (Exception ex)
            {
                this.BeginInvoke((MethodInvoker) delegate
                {
                    fModuleError(_sModule);
                });
                TraceManager.Add("Download check failed:" + _sModule);
                ErrorManager.AddToLog("Download check failed.", ex);
                //   e.Result = null;
            }
        }
コード例 #2
0
ファイル: CommunUpdater.cs プロジェクト: VLiance/Cwc-src
        /// <summary>
        /// Does the actual work on background
        /// </summary>
        public void WorkerDoWork(Object sender, DoWorkEventArgs e)
        {
            try
            {
                TraceManager.Add("--Update check start.");
                WebRequest request = WebRequest.Create(URL);
                request.Proxy = null; //Important remove slow proxy down
                WebResponse  response = request.GetResponse();
                Stream       stream   = response.GetResponseStream();
                StreamReader reader   = new StreamReader(stream);

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    fReadHttpInfoModule(line);
                }
                bReadFinished = true;

                this.BeginInvoke((MethodInvoker) delegate
                {
                    fUpdateStatus();
                });
            }
            catch (Exception ex)
            {
                TraceManager.Add("Update check failed." + ex);
                ErrorManager.AddToLog("Update check failed.", ex);
                e.Result = null;
            }
        }
コード例 #3
0
 /// <summary>
 /// Ensures that a file has been updated after zip extraction
 /// </summary>
 public static void EnsureUpdatedFile(String file)
 {
     try
     {
         String newFile = file + ".new";
         String delFile = file + ".del";
         if (File.Exists(newFile))
         {
             String oldFile = newFile.Substring(0, newFile.Length - 4);
             if (File.Exists(oldFile))
             {
                 File.Copy(newFile, oldFile, true);
                 File.Delete(newFile);
             }
             else
             {
                 File.Move(newFile, oldFile);
             }
         }
         if (File.Exists(delFile))
         {
             File.Delete(file);
             File.Delete(delFile);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Can't update files.", ex);
     }
 }
コード例 #4
0
 /// <summary>
 /// Handles the incoming events
 /// </summary>
 public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority prority)
 {
     if (e.Type == EventType.UIStarted)
     {
         try
         {
             foreach (Macro macro in this.settingObject.UserMacros)
             {
                 if (macro.AutoRun)
                 {
                     foreach (String entry in macro.Entries)
                     {
                         String[] parts = entry.Split(new Char[1] {
                             '|'
                         });
                         PluginBase.MainForm.CallCommand(parts[0], parts[1]);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             ErrorManager.AddToLog("Macro AutoRun Failed.", ex);
         }
     }
     if (e.Type == EventType.ApplySettings)
     {
         this.UpdateMenuShortcut();
     }
 }
コード例 #5
0
 public ServerSocket(String address, Int32 port)
 {
     if (address == null || address == "invalid")
     {
         isInvalid = true;
         return;
     }
     try
     {
         ipAddress = IPAddress.Parse(address);
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Invalid IP address: " + address, ex);
     }
     portNum = port;
 }
コード例 #6
0
 public bool ConnectClient()
 {
     if (bridgeNotFound)
     {
         return(false);                // don't fail repeatedly if bridge is not running
     }
     try
     {
         conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
         conn.Connect(new IPEndPoint(ipAddress, portNum));
         SetupReceiveCallback(conn);
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Failed to connect to: " + ipAddress + ":" + portNum, ex);
         bridgeNotFound = true;
         return(false);
     }
     return(true);
 }
コード例 #7
0
 /// <summary>
 /// Does the actual work on background
 /// </summary>
 private void WorkerDoWork(Object sender, DoWorkEventArgs e)
 {
     try
     {
         WebRequest   request  = WebRequest.Create(URL);
         WebResponse  response = request.GetResponse();
         Stream       stream   = response.GetResponseStream();
         StreamReader reader   = new StreamReader(stream);
         String       version  = reader.ReadLine();       // Read version
         String       download = reader.ReadLine();       // Read download
         String       product  = Application.ProductName; // Internal version
         String       current  = product.Substring(13, product.IndexOf(" for") - 13);
         stream.Close(); response.Close();                // Close all resources
         e.Result = new UpdateInfo(current, version, download);
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Update check failed.", ex);
         e.Result = null;
     }
 }
コード例 #8
0
 /// <summary>
 /// Runs the macros that have autorun enabled
 /// </summary>
 private void RunAutoRunMacros()
 {
     try
     {
         foreach (Macro macro in this.settingObject.UserMacros)
         {
             if (macro.AutoRun)
             {
                 foreach (String entry in macro.Entries)
                 {
                     String[] parts = entry.Split(new Char[1] {
                         '|'
                     });
                     PluginBase.MainForm.CallCommand(parts[0], parts[1]);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Macro AutoRun Failed.", ex);
     }
 }
コード例 #9
0
 static string DetectIP()
 {
     try
     {
         string issue = "Unable to find a gateway";
         foreach (NetworkInterface f in NetworkInterface.GetAllNetworkInterfaces())
         {
             issue += "\n" + f.Name + ", " + f.Description;
             if (f.OperationalStatus == OperationalStatus.Up)
             {
                 foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
                 {
                     return(d.Address.ToString());
                 }
             }
         }
         throw new Exception(issue);
     }
     catch (Exception ex)
     {
         ErrorManager.AddToLog("Gateway detection", ex);
     }
     return(null);
 }
コード例 #10
0
 /// <summary>
 /// Processes the specified commands
 /// </summary>
 private void ProcessCommands(Object sender, DoWorkEventArgs e)
 {
     try
     {
         Int32 count = 0;
         Int32 total = this.commands.Entries.Count;
         foreach (Command command in this.commands.Entries)
         {
             if (command.Number > Globals.Settings.LatestCommand)
             {
                 String data = this.ProcessArguments(command.Data);
                 if (command.Action.ToLower() == "copy")
                 {
                     String[] args = data.Split(';');
                     if (Directory.Exists(args[0]))
                     {
                         FolderHelper.CopyFolder(args[0], args[1]);
                     }
                     else
                     {
                         if (File.Exists(args[0]) && args.Length == 3 && args[2] == "keep-old")
                         {
                             File.Copy(args[0], args[1], false);
                         }
                         else if (File.Exists(args[0]))
                         {
                             File.Copy(args[0], args[1], true);
                         }
                     }
                 }
                 else if (command.Action.ToLower() == "move")
                 {
                     String[] args = data.Split(';');
                     if (Directory.Exists(args[0]))
                     {
                         FolderHelper.CopyFolder(args[0], args[1]);
                         Directory.Delete(args[0], true);
                     }
                     else if (File.Exists(args[0]))
                     {
                         File.Copy(args[0], args[1], true);
                         File.Delete(args[0]);
                     }
                 }
                 else if (command.Action.ToLower() == "delete")
                 {
                     if (Directory.Exists(data))
                     {
                         Directory.Delete(data, true);
                     }
                     else if (File.Exists(data))
                     {
                         File.Delete(data);
                     }
                 }
                 else if (command.Action.ToLower() == "syntax")
                 {
                     CleanupManager.RevertConfiguration(false);
                 }
                 else if (command.Action.ToLower() == "create")
                 {
                     Directory.CreateDirectory(data);
                 }
             }
             count++;
             Int32 percent = (100 * count) / total;
             this.worker.ReportProgress(percent);
         }
         e.Result = true;
     }
     catch (Exception ex)
     {
         e.Result = false;
         ErrorManager.AddToLog("Init failed.", ex);
         this.worker.CancelAsync();
     }
 }
コード例 #11
0
        public void CheckAS3(string filename, string flexPath, string src)
        {
            if (running)
            {
                return;
            }

            // let other plugins preprocess source/handle checking
            Hashtable data = new Hashtable();

            data["filename"] = filename;
            data["src"]      = src;
            data["ext"]      = Path.GetExtension(filename);
            DataEvent de = new DataEvent(EventType.Command, "AS3Context.CheckSyntax", data);

            EventManager.DispatchEvent(this, de);
            if (de.Handled)
            {
                return;
            }

            src      = (string)data["src"];
            filename = (string)data["filename"];
            if (".mxml" == (string)data["ext"]) // MXML not supported by ASC without preprocessing
            {
                return;
            }

            string basePath = null;

            if (PluginBase.CurrentProject != null)
            {
                basePath = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath);
            }
            flexPath = PathHelper.ResolvePath(flexPath, basePath);
            // asc.jar in FlexSDK
            if (flexPath != null && Directory.Exists(Path.Combine(flexPath, "lib")))
            {
                ascPath = Path.Combine(flexPath, "lib\\asc.jar");
            }
            // included asc.jar
            if (ascPath == null || !File.Exists(ascPath))
            {
                ascPath = PathHelper.ResolvePath(Path.Combine(PathHelper.ToolDir, "flexlibs/lib/asc.jar"));
            }

            if (ascPath == null)
            {
                if (src != null)
                {
                    return;              // silent checking
                }
                DialogResult result = MessageBox.Show(TextHelper.GetString("Info.SetFlex2OrCS3Path"), TextHelper.GetString("Title.ConfigurationRequired"), MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    IASContext context = ASContext.GetLanguageContext("as3");
                    if (context == null)
                    {
                        return;
                    }
                    PluginBase.MainForm.ShowSettingsDialog("AS3Context", "SDK");
                }
                else if (result == DialogResult.No)
                {
                    PluginBase.MainForm.ShowSettingsDialog("ASCompletion", "Flash");
                }
                return;
            }

            flexShellsPath = CheckResource("FlexShells.jar", flexShellsJar);
            if (!File.Exists(flexShellsPath))
            {
                if (src != null)
                {
                    return;              // silent checking
                }
                ErrorManager.ShowInfo(TextHelper.GetString("Info.ResourceError"));
                return;
            }

            jvmConfig = JvmConfigHelper.ReadConfig(flexPath);

            try
            {
                running = true;
                if (src == null)
                {
                    EventManager.DispatchEvent(this, new NotifyEvent(EventType.ProcessStart));
                }
                if (ascRunner == null || !ascRunner.IsRunning || currentSDK != flexPath)
                {
                    StartAscRunner(flexPath);
                }

                notificationSent = false;
                if (src == null)
                {
                    silentChecking = false;
                    //TraceManager.Add("Checking: " + filename, -1);
                    ASContext.SetStatusText(TextHelper.GetString("Info.AscRunning"));
                    ascRunner.HostedProcess.StandardInput.WriteLine(filename);
                }
                else
                {
                    silentChecking = true;
                    ascRunner.HostedProcess.StandardInput.WriteLine(filename + "$raw$");
                    ascRunner.HostedProcess.StandardInput.WriteLine(src);
                    ascRunner.HostedProcess.StandardInput.WriteLine(filename + "$raw$");
                }
            }
            catch (Exception ex)
            {
                ErrorManager.AddToLog(TextHelper.GetString("Info.CheckError"), ex);
                TraceManager.AddAsync(TextHelper.GetString("Info.CheckError") + "\n" + ex.Message);
            }
        }