Convert C ++ to C # [closed]

0

Well, I'm passing some code that I have, and I'm sure I can pass this code to C #, and I wanted the help of anyone who can help, in the following code below

#include <dirent.h>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <windows.h>

bool extracoes();

int main()
{
    bool saida;
    //"Interface"
    saida = extracoes();
    if(saida)
        std::cout<<"Copias concluidas!!!\n\nPressione qualquer tecla para encerrar!";
    else
        std::cout<<"Erro! Executar instalacao como Suporte\n\nPressione qualquer tecla para encerrar...";
    std::cin.get();
}

bool extracoes()
{
    struct dirent *lsdir;
    DIR *dir;
    int qtd=0, i=0;
    bool padrao;
    std::string path;
    dir = opendir("D:\Users\");

    while((lsdir = readdir(dir)) != NULL)
        qtd++;

    std::string users[qtd];
    closedir(dir);

    dir=opendir("D:\Users\");
    while((lsdir = readdir(dir)) != NULL)
    {
        padrao=true;
        std::string aux = lsdir->d_name;
        if(aux.size() == 7)
        {
            for(int j=0; j<7; j++)
            {
                if(!(aux[j]<=57 && aux[j]>=48))
                {
                    padrao=false;
                    break;
                }
            }
        }
        else
            padrao=false;

        if(padrao)
        {
            users[i]=aux;
            i++;
        }
    }
    closedir(dir);

    users[i]    = "Default";
    users[i+1]  = "
#include <dirent.h>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <windows.h>

bool extracoes();

int main()
{
    bool saida;
    //"Interface"
    saida = extracoes();
    if(saida)
        std::cout<<"Copias concluidas!!!\n\nPressione qualquer tecla para encerrar!";
    else
        std::cout<<"Erro! Executar instalacao como Suporte\n\nPressione qualquer tecla para encerrar...";
    std::cin.get();
}

bool extracoes()
{
    struct dirent *lsdir;
    DIR *dir;
    int qtd=0, i=0;
    bool padrao;
    std::string path;
    dir = opendir("D:\Users\");

    while((lsdir = readdir(dir)) != NULL)
        qtd++;

    std::string users[qtd];
    closedir(dir);

    dir=opendir("D:\Users\");
    while((lsdir = readdir(dir)) != NULL)
    {
        padrao=true;
        std::string aux = lsdir->d_name;
        if(aux.size() == 7)
        {
            for(int j=0; j<7; j++)
            {
                if(!(aux[j]<=57 && aux[j]>=48))
                {
                    padrao=false;
                    break;
                }
            }
        }
        else
            padrao=false;

        if(padrao)
        {
            users[i]=aux;
            i++;
        }
    }
    closedir(dir);

    users[i]    = "Default";
    users[i+1]  = "%pre%";
    i           = 0;
    padrao      = true;

    //Config Global
    if(system("Xcopy kds_kodak c:\ProgramData\kds_kodak /v /e /y /h > nul") == 0)
        std::cout<<"Extracao Config_Globais concluida\n\n";
    else
    {
        padrao = false;
        std::cout<<"Erro na extracao Config_Globais\n";
    }
    //Config default e usuários
    while(users[i].compare("%pre%"))
    {
        std::cout<<"Copiando...\n";
        path = "Xcopy \"Smart Touch\" \"d:\Users\";
        path += users[i]+"\AppData\Local\Smart Touch\\" /v /e /y /h > nul";

        if(system(path.c_str()) == 0)
            std::cout<<"Copia do usuario "<<users[i]<<" concluida!!\n\n";
        else
        {
            std::cout<<"Copia do usuario "<<users[i]<<" nao concluida!!\n\n";
            padrao = false;
        }
        i++;
    }
    return padrao;
    std::cin.get();
}
"; i = 0; padrao = true; //Config Global if(system("Xcopy kds_kodak c:\ProgramData\kds_kodak /v /e /y /h > nul") == 0) std::cout<<"Extracao Config_Globais concluida\n\n"; else { padrao = false; std::cout<<"Erro na extracao Config_Globais\n"; } //Config default e usuários while(users[i].compare("%pre%")) { std::cout<<"Copiando...\n"; path = "Xcopy \"Smart Touch\" \"d:\Users\"; path += users[i]+"\AppData\Local\Smart Touch\\" /v /e /y /h > nul"; if(system(path.c_str()) == 0) std::cout<<"Copia do usuario "<<users[i]<<" concluida!!\n\n"; else { std::cout<<"Copia do usuario "<<users[i]<<" nao concluida!!\n\n"; padrao = false; } i++; } return padrao; std::cin.get(); }
    
asked by anonymous 03.09.2014 / 00:27

1 answer

2

The ideal would not even be to respond, since a translation of code from one language to another can be done with the use of a tool like this:

link

In the meantime, I'll put some useful directions in the answer when converting your code.

1. Create an Application Console

This is a console application. Start by creating a project in Visual Studio as Console Application .

2. Entry and exit

cout << "Olá, Mundo";

Can be replaced by

Console.WriteLine("Olá, Mundo");

And also:

cin.get();

Can be replaced by:

Console.ReadKey();

3. Shell Commands

To run a Shell command, use:

System.Diagnostics.Process.Start("CMD.exe", "Xcopy kds_kodak c:\ProgramData\kds_kodak /v /e /y /h > nul");

Other codes

Having these baselines, just adapt them to the logic you need.

    
03.09.2014 / 00:48