Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Потихоньку переделываю с С# на С++
#1
Все же от код шарпа:

Код:
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;

namespace Teragame.logger
{
    public class Log
    {
        static bool cf = false;    
        public static void warning(string text)
        {            
            (Application.OpenForms[0] as MainInterface).LogBox.Invoke((MethodInvoker)(delegate()
            {          
                if ((Application.OpenForms[0] as MainInterface).LogBox.Text.Length > 0)
                {
                    (Application.OpenForms[0] as MainInterface).LogBox.AppendText(Environment.NewLine);
                }
                (Application.OpenForms[0] as MainInterface).LogBox.AppendText(text);
                (Application.OpenForms[0] as MainInterface).LogBox.Select((Application.OpenForms[0] as MainInterface).LogBox.Text.Length - text.Length, text.Length);
                (Application.OpenForms[0] as MainInterface).LogBox.SelectionColor = Color.Yellow;
            }));
            if (cf) tw.WriteLine(text);
        }
        public static void error(string text)
        {
            (Application.OpenForms[0] as MainInterface).LogBox.Invoke((MethodInvoker)(delegate() {
            if ((Application.OpenForms[0] as MainInterface).LogBox.Text.Length > 0)
            {
                (Application.OpenForms[0] as MainInterface).LogBox.AppendText(Environment.NewLine);
            }
            (Application.OpenForms[0] as MainInterface).LogBox.AppendText(text);
            (Application.OpenForms[0] as MainInterface).LogBox.Select((Application.OpenForms[0] as MainInterface).LogBox.Text.Length - text.Length, text.Length);
            (Application.OpenForms[0] as MainInterface).LogBox.SelectionColor = Color.Red;
            }));
            if (cf) tw.WriteLine(text);
        }
        public static void info(string text)
        {
            (Application.OpenForms[0] as MainInterface).LogBox.Invoke((MethodInvoker)(delegate()
            {
                if ((Application.OpenForms[0] as MainInterface).LogBox.Text.Length > 0)
                {
                    (Application.OpenForms[0] as MainInterface).LogBox.AppendText(Environment.NewLine);
                }
                (Application.OpenForms[0] as MainInterface).LogBox.AppendText(text);
            }));
            if (cf) tw.WriteLine(text);
        }
        public static void extra_info(string text)
        {
            (Application.OpenForms[0] as MainInterface).LogBox.Invoke((MethodInvoker)(delegate()
            {
                if ((Application.OpenForms[0] as MainInterface).LogBox.Text.Length > 0)
                {
                    (Application.OpenForms[0] as MainInterface).LogBox.AppendText(Environment.NewLine);
                }
                (Application.OpenForms[0] as MainInterface).LogBox.AppendText(text);
                (Application.OpenForms[0] as MainInterface).LogBox.Select((Application.OpenForms[0] as MainInterface).LogBox.Text.Length - text.Length, text.Length);
                (Application.OpenForms[0] as MainInterface).LogBox.SelectionColor = Color.Lime;
            }));
            if (cf) tw.WriteLine(text);
        }
        static string name;
        static TextWriter tw;
        public static void form()
        {
            if (!cf)
                return;

            name = @"log\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".log";
            tw = File.CreateText(name);
            extra_info("Log file created " + name);
        }
    }
}

От код С++

Код:
#pragma once

using namespace System;
using namespace System::IO;
using namespace System::Windows::Forms;
using namespace System::Drawing;



namespace Teragame
{
    namespace logger
    {
        class Log
        {
        private:
            static bool cf;
        public:
            static void warning (std::string text)
            {
                (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Invoke((MethodInvoker)(delegate()
                {
                    if ((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length > 0)
                    {
                        (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText("\r\n");
                    }
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText(text);
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Select((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length - text.length(), text.length());
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->SelectionColor = Color::Yellow;
                }
               ));
                if (cf)
                    tw->WriteLine(text);
            }
            static void error(std::string text)
            {
                (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Invoke((MethodInvoker)(delegate()
                {
                    if ((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length > 0)
                    {
                        (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText("\r\n");
                    }
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText(text);
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Select((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length - text.length(), text.length());
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->SelectionColor = Color::Red;
                }
               ));
                if (cf)
                    tw->WriteLine(text);
            }
            static void info(std::string text)
            {
                (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Invoke((MethodInvoker)(delegate()
                {
                    if ((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length > 0)
                    {
                        (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText("\r\n");
                    }
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText(text);
                }
               ));
                if (cf)
                    tw->WriteLine(text);
            }
            static void extra_info(std::string text)
            {
                (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Invoke((MethodInvoker)(delegate()
                {
                    if ((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length > 0)
                    {
                        (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText("\r\n");
                    }
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText(text);
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Select((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length - text.length(), text.length());
                    (dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->SelectionColor = Color::Lime;
                }
               ));
                if (cf)
                    tw->WriteLine(text);
            }
        private:
            static std::string name;
            static TextWriter *tw;
        public:
            static void form()
            {
                if (!cf)
                    return;
                name = "log\\" + DateTime::Now.ToString("yyyy-MM-dd HH-mm-ss") + ".log";
                tw = File::CreateText(name);
                extra_info("Log file created " + name);
            }
        };
    }
}

std:Confusedtring
error: namespace "std" не содержит члена "string"
Ответ
#2
Посмеялся =)
Зачем??
Ответ
#3
все дал чехлов String с большой буквы))) ребят как выполнить это на С++?
С#
namespace Teragame.logger
{
public class Log
{
static bool cf = false;
public static void warning(string text)
{
(Application.OpenForms[0] as MainInterface).LogBox.Invoke((MethodInvoker)(delegate()
{
if ((Application.OpenForms[0] as MainInterface).LogBox.Text.Length > 0)
{
(Application.OpenForms[0] as MainInterface).LogBox.AppendText(Environment.NewLine);
}
(Application.OpenForms[0] as MainInterface).LogBox.AppendText(text);
(Application.OpenForms[0] as MainInterface).LogBox.Select((Application.OpenForms[0] as MainInterface).LogBox.Text.Length - text.Length, text.Length);
(Application.OpenForms[0] as MainInterface).LogBox.SelectionColor = Color.Yellow;
}));
if (cf) tw.WriteLine(text);
}

C++
namespace Teragame
{
namespace logger
{
class Log
{
private:
static bool cf=false;
public:
static void warning (String text)
{
(dynamic_cast<~MyInterface>(Application::OpenForms[0]))->LogBox->Invoke((MethodInvoker)(delegate()
{
if ((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length > 0)
{
(dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText("\r\n");
}
(dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->AppendText(text);
(dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Select((dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->Text.Length - text.length(), text.length());
(dynamic_cast<MainInterface*>(Application::OpenForms[0]))->LogBox->SelectionColor = Color::Yellow;
}
));
if (cf)
tw->WriteLine(text);
}

Еще чо-то MainInterface не опредиляеться хоть и есть такой класс. Потом если ставлю ~MainInterface то нечего не происходит, то есть не пишет ошибку. Советчик нечего не говорит.

Добавлено через 9 минут
Gattsu Написал:Посмеялся =)
Зачем??
получать - знания, навыки, практику. Это с сурсов что выложили.
Ответ
#4
Ну сначала "хотя бы" язык С++ выучите

Понимаете что С# это не С++ и копировать тупо код чтобы каким-то чудом он заработал
Ответ
#5
Вопрос зачем от Gattsu вполне правильный.

Сюда с Вашего кода, Вы переписываете всё с С# на C++/CLI, в итоге вы получите тот же exe'шник для .Net. С таким же успехом вы можете переписать на Basic.Net.

(Это несколько странно учитывая то, что Вы рветесь в сторону чистого C)
НЛО прилетело и оставило подпись здесь.
Ответ
#6
посудить по вашей логике фраемворки нета не использовать вощеSmile?????

Добавлено через 1 час 27 минут
#define #GAMESERVER#

using namespace System;

#include "Properties/Resources.Designer.h"
#include "logger/Log.h"
#include "Cfg.h"
#include "IdFactory.h"
#include "SQLjec.h"
#include "ClientManager.h"

private ref class GameServer
{
private:
static GameServer^ gs = gcnew GameServer();
public:
static GameServer^ getInstance()
{
return gs;
}
protected:
TcpListener^ _listener;
public:
GameServer()
{

XElement^ xml = XElement:Tonguearse(Properties::Resources::tera);
if (int:Tonguearse(xml->Element("license")->Element("key")->Attribute("value")->Value) == 1234)
{
logger::Log::form();
Cfg::init("all");
IdFactory::getInstance()->init();
SQLjec::getInstance();
logger::Log::extra_info("Server start");
_listener = gcnew TcpListener(IPAddress:Tonguearse(Cfg::SERVER_HOST), Cfg::SERVER_PORT);
_listener->Start();
TcpClient^ clientSocket = default(TcpClient);
while (true)
{
clientSocket = _listener->AcceptTcpClient();
accept(clientSocket);
}
}
else
{
logger::Log::error("Programm not activate");
return;
}
}
private:
void accept(TcpClient^ clientSocket)
{
ClientManager::getInstance()->addClient(clientSocket);
}
};


#endif
Ответ
#7
За Вас тут никто код переписывать не будет.
Кроме того на форуме есть BB-код для отрывков кода (это на будущее)

Оффтоп
НЛО прилетело и оставило подпись здесь.
Ответ
#8
Логики у оригинала нет, код как после обфускации, зачем "это" переносить? Просто подсмотрите encrypt\decrypt и пишите с 0 на своем C++.
Ответ
#9
praetorianec Написал:Добавлено через 9 минут

получать - знания, навыки, практику. Это с сурсов что выложили.

Практика показывает, для того чтобы что-то отложилось в голове, нужно писать самому и с 0-ля, а не переписывать уже готовое под копирку или шаблон.
[Изображение: 61b684.png]
Ответ
#10
praetorianec Написал:все дал чехлов String с большой буквы))) ребят как выполнить это на С++?

Еще чо-то MainInterface не опредиляеться хоть и есть такой класс. Потом если ставлю ~MainInterface то нечего не происходит, то есть не пишет ошибку. Советчик нечего не говорит.

С std:Confusedtring банальнейшая ошибка. Вы ничему не научитесь, бездумно перенося код с одного языка на другой.
Что значит "ставлю ~MainInterface()"? Вы знаете, что ~MainInterface() - это деструктор и он, в общем случае, не требует вызова вручную (более того, это может привести к серьезным ошибкам)?
// aka Deft
Ответ


Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)