/// <summary> /// 左スティック /// </summary> /// <param name="stickID"></param> /// <returns></returns> public bool IsLeftSticksPush(StickID stickID) { bool current = false; if (stickID == StickID.Up) { if (1.0f == GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y) { current = true; } } if (stickID == StickID.Down) { if (-1.0f == GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y) { current = true; } } if (stickID == StickID.Left) { if (-1.0f == GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X) { current = true; } } if (stickID == StickID.Right) { if (1.0f == GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X) { current = true; } } return(current); }
/// <summary> /// Starts the writing on the USB Sticks. /// </summary> /// <remarks>Documented by Dev08, 2008-10-08</remarks> private void SubThreadProcess(object drive) { OnSubThreadBegin(drive); DriveInfo driveInfo = drive as DriveInfo; string root = driveInfo.RootDirectory.ToString(); #region COPY if (CopyContent) { //1. Delete everything on Stick OnSubThreadStatusMessage("Formatting drive...", driveInfo); try { FormatDrive(root); } catch (Exception e) { OnSubThreadError("Could not format drive! --> " + e.ToString(), driveInfo); return; } OnSubThreadFormattingFinish(driveInfo); //2. Write files from zip file onto the stick int counter = 0; foreach (string filename in zipFilenames) //Write the structure of the ZipFile { try { string absoluteFilename = Path.Combine(root, filename); if (zipFileType[counter] == StickFactory.MainForm.FileDirType.Directory) { Directory.CreateDirectory(absoluteFilename); if (folderAttributes.ContainsKey(filename.Replace('/', '\\').Trim(new char[] { '\\', '/' }))) { (new DirectoryInfo(absoluteFilename.Trim(new char[] { '\\', '/' }))).Attributes = folderAttributes[filename.Replace('/', '\\').Trim(new char[] { '\\', '/' })]; } } else { FileStream fs = File.Create(absoluteFilename); fs.Write(zipFileContentList[counter], 0, Convert.ToInt32(zipFileSizes[counter])); fs.Close(); //File.AppendAllText("log.txt", string.Format("Setting on File {0}: {1}\r\n", absoluteFilename, fileAttributes[filename].ToString())); if (fileAttributes.ContainsKey(filename)) { File.SetAttributes(absoluteFilename, fileAttributes[filename]); } } } catch (FileNotFoundException) { OnSubThreadError("File not found! Probably the stick was removed...", driveInfo); return; } catch (DirectoryNotFoundException) { OnSubThreadError("Directory not found! Probably the stick was removed...", driveInfo); return; } catch (IOException e) { OnSubThreadError("Could not access File! --> " + e.ToString(), driveInfo); return; } counter++; OnSubThreadWriting(counter, zipFilenames.Count, (DriveInfo)drive); } OnSubThreadContentWritten(driveInfo); //3. Set VolumeId: SetVolumeId(root, StickID); OnSubThreadIdSet(driveInfo); } #endregion #region CHECK if (CheckContent) { //1. Check volume serial string expectedVolumeSerial = StickID.Replace("-", ""); string volumeSerial = GetVolumeSerial((DriveInfo)drive); if (expectedVolumeSerial != volumeSerial) { OnSubThreadError(string.Format("Volume serial wrong: expected {0}, actually {1}", expectedVolumeSerial, volumeSerial), (DriveInfo)drive); return; } //2. Check file contents int counter = 0; foreach (string filename in zipFilenames) { bool fileSuccessful = true; string absoluteFilename = Path.Combine(root, filename); string fileError = string.Empty; if (zipFileType[counter] == StickFactory.MainForm.FileDirType.Directory) { if (!Directory.Exists(absoluteFilename)) { fileSuccessful = false; fileError = "Directory does not exist: " + absoluteFilename; } else { try { DirectoryInfo folder = new DirectoryInfo(absoluteFilename); if (folderAttributes.ContainsKey(filename.Replace('/', '\\').Trim(new char[] { '\\', '/' }))) { if (folder.Attributes != folderAttributes[filename.Replace('/', '\\').Trim(new char[] { '\\', '/' })]) { fileSuccessful = false; fileError = "Folder Attributes does not match: " + absoluteFilename; } } else { if (!(folder.Attributes == System.IO.FileAttributes.Normal || folder.Attributes == System.IO.FileAttributes.Archive || folder.Attributes == System.IO.FileAttributes.Directory)) { fileSuccessful = false; fileError = "Folder Attributes does not match: " + absoluteFilename; } } } catch (FileNotFoundException) { OnSubThreadError("File not found! Probably the stick was removed...", (DriveInfo)drive); return; } catch (DirectoryNotFoundException) { OnSubThreadError("Directory not found! Probably the stick was removed...", (DriveInfo)drive); return; } } } else { if (!File.Exists(absoluteFilename)) { fileSuccessful = false; fileError = "File does not exist: " + absoluteFilename; } else { try { FileInfo file = new FileInfo(absoluteFilename); if (file.Length != zipFileSizes[counter]) { fileSuccessful = false; fileError = "File size does not correspond: " + absoluteFilename; } if (fileAttributes.ContainsKey(filename)) { if (file.Attributes != fileAttributes[filename]) { fileSuccessful = false; fileError = "File Attributes does not match: " + absoluteFilename; } } else { if (!(file.Attributes == System.IO.FileAttributes.Normal || file.Attributes == System.IO.FileAttributes.Archive)) { fileSuccessful = false; fileError = "File Attributes does not match: " + absoluteFilename; } } } catch (FileNotFoundException) { OnSubThreadError("File not found! Probably the stick was removed...", (DriveInfo)drive); return; } catch (DirectoryNotFoundException) { OnSubThreadError("Directory not found! Probably the stick was removed...", (DriveInfo)drive); return; } } } if (!fileSuccessful) { OnSubThreadError(fileError, (DriveInfo)drive); return; //cancel checking process } counter++; if (counter % 25 == 0) { OnSubThreadWriting(counter, zipFilenames.Count, (DriveInfo)drive); } } //3. Check for any other (unwanted) files/directories int filecount = 0; int directorycount = 0; List <string> imagedirs = new List <string>(); counter = 0; foreach (string filename in zipFilenames) { if (zipFileType[counter] == StickFactory.MainForm.FileDirType.Directory) { directorycount++; imagedirs.Add(filename); } else { filecount++; } ++counter; } DirectoryInfo driveRoot = ((DriveInfo)drive).RootDirectory; FileInfo[] foundfiles = driveRoot.GetFiles("*", SearchOption.AllDirectories); int foundfilecount = foundfiles.Length; DirectoryInfo[] founddirs = driveRoot.GetDirectories("*", SearchOption.AllDirectories); int founddirectorycount = founddirs.Length; if (foundfilecount != filecount) { OnSubThreadError(string.Format("File count wrong: expected {0}, actually {1}", filecount, foundfilecount), (DriveInfo)drive); return; } if (founddirectorycount != directorycount) { bool overrideFailded = true; foreach (DirectoryInfo info in founddirs) { string pathToCheck = info.FullName.Remove(0, 3).Replace(@"\", @"/") + @"/"; if (!imagedirs.Contains(pathToCheck)) { if (info.GetFiles("*", SearchOption.TopDirectoryOnly).Length != 0) { overrideFailded = false; break; } } } if (!overrideFailded) { OnSubThreadError(string.Format("Directory count wrong: expected {0}, actually {1}", directorycount, founddirectorycount), (DriveInfo)drive); return; } } } #endregion Thread.Sleep(ejectionDelay); EjectDrive(root); OnSubThreadFinished(drive); }
/// <summary> /// /// </summary> /// <param name="targetStick">An ID of stick on which this operation is performed.</param> /// <param name="targetXAngle">The position of stick in X direction, after this operation is performed.</param> /// <param name="targetYAngle">The position of stick in Y direction, after this operation is performed.</param> public OperateStick(StickID targetStick, StickAngle targetXAngle, StickAngle targetYAngle) : this(targetStick, (byte)targetXAngle, (byte)targetYAngle) { }
/// <summary> /// /// </summary> /// <param name="targetStick">An ID of stick on which this operation is performed.</param> /// <param name="targetXAngle">The angle of stick in X direction, after this operation is performed. /// 128 represents neutral position. 0 and 225 represents maximum tilting.</param> /// <param name="targetYAngle">The angle of stick in Y direction, after this operation is performed.</param> public OperateStick(StickID targetStick, byte targetXAngle, byte targetYAngle) : base((byte)targetStick) { this.Initialize(targetXAngle, targetYAngle); }
/// <summary> /// /// </summary> /// <param name="stickID">An ID of button that changed its state.</param> /// <param name="state">The angle of stick in X direction,</param> public StickStateChangedEventArgs(StickID stickID, byte x, byte y) { this.StickID = stickID; this.X = x; this.Y = y; }