Пример #1
0
        public void ReadLoop()
        {
            var reader = new GiderosMessageReader(soc);

            while (true)
            {
                ReceivedGiderosMessage msg = reader.TryTakeMessageFromBuffer();
                if (msg == null)
                {
                    if (reader.ReceiveMore() == 0)
                    {
                        return;
                    }
                    continue;
                }

                byte msgType = msg.ReadByte();
                switch (msgType)
                {
                case GiderosMessageType.Output:
                    HandleOutput(msg);
                    break;

                case GiderosMessageType.FileList:
                    HandleFileList(msg);
                    break;

                default:
                    logger.X_Log(LogType.Warning, "unknown message:" + msgType);
                    break;
                }
            }
        }
Пример #2
0
 // Output Gideros print() statements to VSCode debug console
 void HandleOutput(ReceivedGiderosMessage msg)
 {
     /*
      * 5/1/2021 - Changed output type to "Info" because "PlayerOutput"
      * does not append new lines for some reason.
      */
     //logger.X_Log(LogType.PlayerOutput, msg.ReadString());
     logger.X_Log(LogType.Info, msg.ReadString());
 }
Пример #3
0
        void HandleFileList(ReceivedGiderosMessage msg)
        {
            // void Application::dataReceived(const QByteArray& d)
            // in gdrdeamon/application.cpp

            Queue <KeyValuePair <string, string> > fileQueue = new Queue <KeyValuePair <string, string> >();

            Dictionary <string, string> localFileMap        = new Dictionary <string, string>();
            Dictionary <string, string> localFileMapReverse = new Dictionary <string, string>();

            foreach (var e in fileList)
            {
                localFileMap[e.Key]          = e.Value;
                localFileMapReverse[e.Value] = e.Key;
            }

            Dictionary <string, KeyValuePair <int, byte[]> > remoteFileMap = new Dictionary <string, KeyValuePair <int, byte[]> >();

            while (msg.IsEOB() == false)
            {
                var file = msg.ReadString();
                if (file[0] == 'F')
                {
                    int    age = msg.ReadInt();
                    byte[] md5 = msg.ReadBytes(16);
                    remoteFileMap[file.Substring(1)] =
                        new KeyValuePair <int, byte[]>(age, md5);
                }
                else if (file[0] == 'D')
                {
                }
            }

            // delete unused files
            foreach (var iter in remoteFileMap)
            {
                if (localFileMap.ContainsKey(iter.Key) == false)
                {
                    //printf("deleting: %s\n", qPrintable(iter->first));
                    NewMessage(GiderosMessageType.DeleteFile)
                    .AppendString(iter.Key)
                    .Send();
                    logger.X_Log(LogType.Info, "delete " + iter.Key);
                }
            }

            // upload files
            string path = Path.GetDirectoryName(projectFileName);

            foreach (var iter in localFileMap)
            {
                KeyValuePair <int, byte[]>?riter = remoteFileMap.Find(iter.Key);

                string localfile = Path.Combine(path, iter.Value);

                bool send = false;
                if (riter.HasValue == false)
                {
                    //printf("always upload: %s\n", qPrintable(iter->first));
                    send = true;
                }
                else
                {
                    int    localage  = Util.FileAge(localfile);
                    int    remoteage = riter.Value.Key;
                    byte[] localmd5  = md5[iter.Value].Value;
                    byte[] remotemd5 = riter.Value.Value;

                    if (localage < remoteage || localmd5.SequenceEqual(remotemd5) == false)
                    {
                        //printf("upload new file: %s\n", qPrintable(iter->first));
                        send = true;
                    }
                }

                if (send == true)
                {
                    fileQueue.Enqueue(new KeyValuePair <string, string>(iter.Key, localfile));
                }
                else
                {
                    //printf("don't upload: %s\n", qPrintable(iter->first));
                }
            }

            List <KeyValuePair <string, bool> > topologicalSort =
                dependencyGraph.TopologicalSort();

            List <string> luaFilesToPlay = topologicalSort
                                           .Where(x => x.Value == false)
                                           .Select(x => localFileMapReverse[x.Key])
                                           .ToList();

            //---------------------------------------------------------
            // 여기부터 void Application::timer()
            var cfolderSent = new HashSet <string>();

            while (fileQueue.Count > 0)
            {
                string s1 = fileQueue.Peek().Key;
                string s2 = fileQueue.Peek().Value;
                fileQueue.Dequeue();

                // create remote directories
                var dir = Path.GetDirectoryName(s1);
                if (cfolderSent.Contains(dir))
                {
                    // pass
                }
                else
                {
                    cfolderSent.Add(dir);
                    NewMessage(GiderosMessageType.CreateFolder)
                    .AppendString(dir)
                    .Send();
                    //logger(LogType.Info, "cfolder " + dir);
                }

                string fileName = Path.Combine(path, s2);

                try
                {
                    byte[] bytes = File.ReadAllBytes(fileName);

                    NewMessage(GiderosMessageType.File)
                    .AppendString(s1)
                    .AppendByteArray(bytes)
                    .Send();
                    logger.X_Log(LogType.Info, "send " + s1);
                }
                catch (FileNotFoundException)
                {
                    // md5 계산에서 이미 경고를 냈으므로
                    // 여기에선 무시한다
                }
            }
            logger.X_Log(LogType.Info, "Uploading finished.");

            SendProjectProperties();

            //-----------------------------------------------
            var playMsg = NewMessage(GiderosMessageType.Play);

            foreach (string f in luaFilesToPlay)
            {
                //logger(LogType.Info, "play " + f);
                playMsg.AppendString(f);
            }
            playMsg.Send();
        }
Пример #4
0
 void HandleOutput(ReceivedGiderosMessage msg)
 {
     logger.X_Log(LogType.PlayerOutput, msg.ReadString());
 }