Ejemplo n.º 1
0
        private void tempConnectionButton_Click(object sender, EventArgs e)
        {
            String        tempMAC = tempDeviceMAC.Text;
            StringBuilder tempIP  = IPMacMapper.InitializeGetIPsAndMac(tempMAC);

            path.Clear();
            path = path.Append("ftp://" + tempIP + ":" + portNo);
            refreshFiles(path);
        }
Ejemplo n.º 2
0
 private void deviceSelected(object sender, EventArgs e)
 {
     try
     {
         path        = path.Clear();
         deviceIndex = deviceList.SelectedIndex;
         IPAddress   = (IPMacMapper.InitializeGetIPsAndMac(MAC[deviceIndex]) + "");
         path        = path.Append("ftp://" + IPAddress + ":" + portNo);
         refreshFiles(path);
     }
     catch (Exception) { }
 }
Ejemplo n.º 3
0
 private void uploadSyncText(String MAC)
 {
     try
     {
         using (var client = new WebClient())
         {
             client.Credentials = new NetworkCredential("", "");
             client.UploadFile("ftp://" + IPMacMapper.InitializeGetIPsAndMac(MAC) + ":" + portNo + "/UnCloud/FilesToSync.txt", uncloudPath + "FilesToSync.txt");
         }
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 4
0
        private void syncFiles(String fileToRead, String subFolder)
        {
            try
            {
                String   list  = File.ReadAllText(fileToRead);
                string[] lines = list.Split(Environment.NewLine.ToCharArray());
                foreach (String line in lines)
                {
                    if (line != "")
                    {
                        String location = line.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "");
                        String fileName = location.Substring(location.LastIndexOf("/") + 1, location.Length - location.LastIndexOf("/") - 1);

                        if (IsFile(line.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "")))
                        {
                            try
                            {
                                location = line.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "");
                                fileName = location.Substring(location.LastIndexOf("/") + 1, location.Length - location.LastIndexOf("/") - 1);
                                String   fileLocation = location.Replace(fileName, "");
                                FileInfo tempFile;
                                tempFile.filePath         = line.Substring(0, 29) + "UnCloud/SyncFilesHashes/HASH" + fileName + ".txt";
                                tempFile.filePath         = tempFile.filePath.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "");
                                tempFile.fileName         = "HASH" + fileName + ".txt";
                                tempFile.downloadLocation = uncloudPath + @"TempDownloads\";

                                downloadFiles(tempFile, false, "");

                                if (!FileEquals(uncloudPath + @"SyncFilesHashes\" + tempFile.fileName, uncloudPath + @"TempDownloads\" + tempFile.fileName))
                                {
                                    tempFile.filePath         = line.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "");
                                    tempFile.fileName         = location.Substring(location.LastIndexOf("/") + 1, location.Length - location.LastIndexOf("/") - 1);
                                    tempFile.downloadLocation = uncloudPath + @"Sync\" + subFolder;
                                    downloadFiles(tempFile, true, "");
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            String newFileToRead = uncloudPath + @"FoldersToSync\" + fileName + ".txt";

                            syncFiles(newFileToRead, subFolder + fileName + @"\");

                            FileInfo tempFile;
                            tempFile.filePath         = line.Substring(0, 29) + "UnCloud/FoldersToSync/" + fileName + ".txt";
                            tempFile.filePath         = tempFile.filePath.Replace(line.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(line.Substring(6, 17)) + "");
                            tempFile.fileName         = fileName + ".txt";
                            tempFile.downloadLocation = uncloudPath + @"TempDownloads\";

                            downloadFiles(tempFile, false, "");

                            if (!FileEquals(uncloudPath + @"FoldersToSync\" + fileName + ".txt", uncloudPath + @"TempDownloads\" + fileName + ".txt"))
                            {
                                String   listPC     = File.ReadAllText(uncloudPath + @"FoldersToSync\" + fileName + ".txt");
                                string[] linesPC    = listPC.Split(Environment.NewLine.ToCharArray());
                                String   listPhone  = File.ReadAllText(uncloudPath + @"TempDownloads\" + fileName + ".txt");
                                string[] linesPhone = listPhone.Split(Environment.NewLine.ToCharArray());
                                foreach (String linePhone in linesPhone)
                                {
                                    if (linePhone != "" && !listPC.Contains(linePhone))
                                    {
                                        tempFile.fileName         = linePhone.Substring(linePhone.LastIndexOf("/") + 1, linePhone.Length - linePhone.LastIndexOf("/") - 1);
                                        tempFile.filePath         = (linePhone.Replace(linePhone.Substring(6, 17), IPMacMapper.InitializeGetIPsAndMac(linePhone.Substring(6, 17)) + ""));
                                        tempFile.downloadLocation = uncloudPath + @"Sync\" + subFolder + fileName + @"\";

                                        downloadFiles(tempFile, true, "");
                                    }
                                }
                                File.Delete(uncloudPath + @"FoldersToSync\" + fileName + ".txt");
                                File.Move(uncloudPath + @"TempDownloads\" + fileName + ".txt", uncloudPath + @"FoldersToSync\" + fileName + ".txt");
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }